1
我試圖在我的數據庫中創建一個表來存儲我的WordPress插件設置。我正在使用下面的代碼,但它不起作用。我沒有得到任何錯誤,但表格沒有被創建,而且似乎該函數根本沒有被執行。無法爲WordPress插件創建MYSQL表
我在做什麼錯?
function ADR_create()
{
global $wpdb;
$table_name = $wpdb->prefix. "Author_detailed_repport";
global $charset_collate;
$charset_collate = $wpdb->get_charset_collate();
global $db_version;
if($wpdb->get_var("SHOW TABLES LIKE ".$table_name) != $table_name)
{ $create_sql = "CREATE TABLE " . $table_name . "(
ADR_id INT(11) NOT NULL auto_increment,
role VARCHAR(30) NOT NULL,
statut INT(1) NOT NULL,
post_number INT(4) NOT NULL,
activate INT(1) NOT NULL,
UNIQUE (ADR_id))$charset_collate;";
}
require_once(ABSPATH . "wp-admin/includes/upgrade.php");
dbDelta($create_sql);
if (!isset($wpdb->Author_detailed_repport))
{
$wpdb->Author_detailed_repport = $table_name;
//add the shortcut so you can use $wpdb->stats
$wpdb->tables[] = str_replace($wpdb->prefix, '', $table_name);
}
}
register_activation_hook(__FILE__, 'ADR_create');
感謝您的更新! – showdev