dbdelta doesn't work (4 posts)

  1. god0fgod
    Posted 6 years ago #

    Quite a simple problem really:

    function create_links_table(){
    	//Create link table
    	global $wpdb;
    	$table_name = $wpdb->prefix . "fim_links";
    	if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
    		$sql = "CREATE TABLE " . $table_name . " (
    		order mediumint(9) NOT NULL AUTO_INCREMENT,
    		href text DEFAULT '#' NOT NULL,
    		id text DEFAULT '0' NOT NULL,
    		block mediumint(9) DEFAULT '1' NOT NULL,
    		PRIMARY KEY  (order)
    		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    		echo "DBINFO:";
    		$result = dbDelta($sql);
    		$sql = "INSERT INTO " . $table_name .
                " (href, id) " .
                "VALUES ('http://crytekuk.info','link_example')";
  2. god0fgod
    Posted 6 years ago #

    I'm surprised, thought this would be a simple problem to experienced people.

    I suppose I'll have to analyse wordpress myself and try to figure it out.

    Alternatively I could try not using dbdelta but that is the proper way, apparently.

  3. WebTechGlobal
    Posted 6 years ago #

    Your doing a variable dump on dbDelta,did you find what I did and it returns a value that states the table was created even when it is not?

    I just wrote a script that uses standard query function to attempt to create the table and then I also run the same query using dbDelta in the event that table was already created then an update with any changes to the table should occur.


  4. sarkazm
    Posted 5 years ago #

    i think it's field name problem.
    you can't use "order" as field name.
    it is reserved.

Topic Closed

This topic has been closed to new replies.

About this Topic