god0fgod
Member
Posted 2 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);
var_dump($result);
$sql = "INSERT INTO " . $table_name .
" (href, id) " .
"VALUES ('http://crytekuk.info','link_example')";
$wpdb->query($sql);
}
}
god0fgod
Member
Posted 2 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.
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.