mysql table 不是由 wordpress 插件创建的
mysql table not creating by wordpress plugin
我正在使用此代码创建 table 但它不起作用。我尝试了单行 SQL 查询,但也不起作用(不确定这是无意义的尝试)。有没有人可以立即帮我解决这个问题?
function rswl_activaiton(){
global $wpdb;
require_once(ABSPATH.'wp-admin/includes/upgrade.php');
$table_name = $wpdb->prefix.'rswl_entries';
$charset = $wpdb->get_charset_collate();
if( $wpdb->get_var( "SHOW TABLES LIKE ".$table_name ) != $table_name ){
$sql = "CREATE TABLE $table_name (
rswl_entry_id INT(10) NOT NULL AUTO_INCREMENT,
rswl_name VARCHAR(100) NOT NULL,
rswl_model VARCHAR(100) NOT NULL,
rswl_date VARCHAR(100) NOT NULL,
rswl_ebay_id VARCHAR(100) NOT NULL,
rswl_email VARCHAR(100) NOT NULL,
rswl_status VARCHAR(100) NOT NULL
PRIMARY KEY (rswl_entry_id)
) $charset;";
dbDelta( $sql );
};
}
register_activation_hook( __FILE__, 'rswl_activaiton' );
我自己解决了这个问题。我在 rswl_status VARCHAR(100) NOT NULL
之后少了一个逗号 (,)
$sql = "CREATE TABLE $table_name (
rswl_entry_id INT(10) NOT NULL AUTO_INCREMENT,
rswl_name VARCHAR(100) NOT NULL,
rswl_model VARCHAR(100) NOT NULL,
rswl_date VARCHAR(100) NOT NULL,
rswl_ebay_id VARCHAR(100) NOT NULL,
rswl_email VARCHAR(100) NOT NULL,
rswl_status VARCHAR(100) NOT NULL,
PRIMARY KEY (rswl_entry_id)
) $charset;";
我正在使用此代码创建 table 但它不起作用。我尝试了单行 SQL 查询,但也不起作用(不确定这是无意义的尝试)。有没有人可以立即帮我解决这个问题?
function rswl_activaiton(){
global $wpdb;
require_once(ABSPATH.'wp-admin/includes/upgrade.php');
$table_name = $wpdb->prefix.'rswl_entries';
$charset = $wpdb->get_charset_collate();
if( $wpdb->get_var( "SHOW TABLES LIKE ".$table_name ) != $table_name ){
$sql = "CREATE TABLE $table_name (
rswl_entry_id INT(10) NOT NULL AUTO_INCREMENT,
rswl_name VARCHAR(100) NOT NULL,
rswl_model VARCHAR(100) NOT NULL,
rswl_date VARCHAR(100) NOT NULL,
rswl_ebay_id VARCHAR(100) NOT NULL,
rswl_email VARCHAR(100) NOT NULL,
rswl_status VARCHAR(100) NOT NULL
PRIMARY KEY (rswl_entry_id)
) $charset;";
dbDelta( $sql );
};
}
register_activation_hook( __FILE__, 'rswl_activaiton' );
我自己解决了这个问题。我在 rswl_status VARCHAR(100) NOT NULL
$sql = "CREATE TABLE $table_name (
rswl_entry_id INT(10) NOT NULL AUTO_INCREMENT,
rswl_name VARCHAR(100) NOT NULL,
rswl_model VARCHAR(100) NOT NULL,
rswl_date VARCHAR(100) NOT NULL,
rswl_ebay_id VARCHAR(100) NOT NULL,
rswl_email VARCHAR(100) NOT NULL,
rswl_status VARCHAR(100) NOT NULL,
PRIMARY KEY (rswl_entry_id)
) $charset;";