1
我想在插件激活創建WordPress數據庫自己的自定義表..This是我的代碼..我定製表不上的WordPress插件激活創建
function __construct()
{
register_activation_hook(__FILE__,array(&$this, 'activate'));
function activate()
{
global $wpdb;
echo "<div class='updated'>Test Plugin Notice</div>";
$table_name = $wpdb->prefix . "dive";
$installed_ver = get_option("divebook_db_table_dive_version");
//Check if the table already exists and if the table is up to date, if not create it
if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name
|| $installed_ver != $divebook_db_table_dive_version) {
$sql = "CREATE TABLE " . $table_name . " (
id mediumint(9) NOT NULL AUTO_INCREMENT,
date bigint(11) DEFAULT '0' NOT NULL,
site tinytext NOT NULL,
description text NOT NULL,
max_depth mediumint(9) NOT NULL,
time mediumint(9) NOT NULL,
UNIQUE KEY id (id)
);";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
update_option("divebook_db_table_dive_version", $divebook_db_table_dive_version);
}
//Add database table versions to options
add_option("divebook_db_table_dive_version", $divebook_db_table_dive_version);
}
}
餘米檢查我的數據庫。沒有新的表格已經創建..Plz看着它..
它全部寫在我的主文件中...... – 2013-04-24 05:40:09
我假設'函數__construct()'是一個類的一部分,你使用'new'運算符實例化那個類,對吧? – Twisted1919 2013-04-24 05:43:13
也,我沒有看到'$ divebook_db_table_dive_version'被定義。另一件事,dbDelta過去給我造成了一些問題,試着用'$ wpdb-> query()'來運行create table查詢。 – Twisted1919 2013-04-24 05:46:10