尝试使用其他方法。WordPress在插件激活期间触发挂钩activate_yourplugin/filename.php
. 您可以使用它来创建表。
function creating_order_tables() {
if(!get_option(\'tables_created\', false)) {
global $wpdb;
$ptbd_table_name = $wpdb->prefix . \'printtextbd_order\';
if ($wpdb->get_var("SHOW TABLES LIKE \'". $ptbd_table_name ."\'" ) != $ptbd_table_name ) {
$sql = \'CREATE TABLE exone(
customer_id INT(20) AUTO_INCREMENT,
customer_name VARCHAR(255),
order_type VARCHAR(255),
choosen_template VARCHAR(255),
order_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY(customer_id))\';
if(!function_exists(\'dbDelta\')) {
require_once(ABSPATH . \'wp-admin/includes/upgrade.php\');
}
dbDelta($sql);
echo "Tables created...";
update_option(\'tables_created\', true);
}
}
}
add_action(\'activate_yourplugin/yourplugin.php\', \'creating_order_tables\');