New plugin not creating table on activation.
-
I am trying to create my first plugin, and after trying to follow a tutorial on creating a sql table on activation (http://codex.ww.wp.xz.cn/Creating_Tables_with_Plugins), it still doesn’t want to create it! Anyone know what is causing this?
$wplinker_db_version = “1.0”;
function wplinker_install () {
global $wpdb;
global $wplinker_db_version;//Create our table (http://codex.ww.wp.xz.cn/Creating_Tables_with_Plugins)
$table_name = $wpdb->prefix . “wplinker”;
if($wpdb->get_var(“show tables like ‘$table_name'”) != $table_name) {
$sql = “CREATE TABLE ” . $table_name . ” (
name tinytext NOT NULL,
url VARCHAR(55) NOT NULL
);”;require_once(ABSPATH . ‘wp-admin/upgrade-functions.php’);
dbDelta($sql);//Add initial data to our table
$linker_name = “Solipsus”;
$linker_url = “http://www.solipsus.com”;$insert = “INSERT INTO ” . $table_name .
” (time, name, text) ” .
“VALUES (‘” . time() . “‘,'” . $wpdb->escape($linker_name) . “‘,'” . $wpdb->escape($linker_url) . “‘)”;$results = $wpdb->query( $insert );
add_option(‘wplinker’, $wplinker);
}
}
The topic ‘New plugin not creating table on activation.’ is closed to new replies.