Help creating wordpress database table
Written By jackosh on Jun. 6, 2007.
4 Comments
Report Note
+ Clip This
I'm trying to write a plugin for WP, and I'm having lots of toruble creating the database. Can anyone help me troubleshoot this code?
$st_db_version = "0.1";
function st_install(){
global $wpdb;
global $st_db_version;
$table_name = $wpdb->prefix . "spinthat";
if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
$sql = "CREATE TABLE " . $table_name . " (
st_id mediumint(9) NOT NULL AUTO_INCREMENT,
st_time bigint(11) DEFAULT '0' NOT NULL,
st_artist tinytext NOT NULL,
st_album tinytext NOT NULL,
st_rating mediumint(6) DEFAULT '0' NOT NULL,
st_blurb text NOT NULL,
st_img VARCHAR(100) NOT NULL,
st_url VARCHAR(100) NOT NULL,
PRIMARY KEY (st_id)
);";
require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
dbDelta($sql);
add_option("st_db_version", $st_db_version);
}
}
add_action('activate_plugindir/wp_spinthat.php', 'st_install');
Thanks!

Scrivs
Written Jun. 6, 2007 / Report /
You pulling any errors?
jackosh
Written Jun. 6, 2007 / Report /
to be honest, I'm not sure how to check any logs- can I?
The plugin installs just fine, but the tables are never added..
Scrivs
Written Jun. 6, 2007 / Report /
Yeah I don't know what's going on, everytime I run over your code it looks legit.
jackosh
Written Jun. 6, 2007 / Report /
well at least I'm not crazy.. thanks for takin a look!