请尝试此代码。
创建一个类似“my\\u db.php”的文件并粘贴以下代码:
global $table_version;
$table_version = "1.0";
function func_table_contactus(){
creat_table_contactus();
}
function creat_table_contactus(){
global $wpdb;
global $table_version;
$table_contactus = $wpdb->prefix."contactus";
$slider_ver = get_option("table_version");
$check_table_contactus = $wpdb->get_var("SHOW TABLES LIKE \'$table_contactus\'");
if($check_table_contactus != $table_contactus || $slider_ver != $table_version ) {
$sql= "CREATE TABLE" .$table_name. "(
id INT(6) UNSIGNED NOT NULL AUTO_INCREMENT,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP
PRIMARY KEY (id)
)";
require_once(ABSPATH.\'wp-admin/includes/upgrade.php\');
dbDelta($sql);
update_option("table_version", $table_version);
}
else{
add_option("table_version", $table_version);
}
}
在插件主文件中
<?php
/*
Plugin Name: ContactUs
Plugin URI:
Description: Simple Plugin Developed for Testing purpose
Version: 1.0.0
Author: rajeshw
Author URI: codelisense.com
*/
require "my_db.php";
add_action(\'plugins_loaded\', \'func_table_contactus\');
希望您能找到解决方案