• 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);
    		var_dump($result);
    		$sql = "INSERT INTO " . $table_name .
                " (href, id) " .
                "VALUES ('https://crytekuk.info','link_example')";
    		$wpdb->query($sql);
    	}
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter god0fgod

    (@god0fgod)

    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.

    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.

    Ryan
    WebTechGlobal

    i think it’s field name problem.
    you can’t use “order” as field name.
    it is reserved.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘dbdelta doesn’t work’ is closed to new replies.