[英]Creating database table when installing a wordpress plugin
I want to create a table into the database upon installing the plugin I've created. 我想在安装我创建的插件时在数据库中创建一个表。
In my main plugin file (index.php): 在我的主插件文件(index.php)中:
register_activation_hook(__FILE__, 'wnm_install');
global $wnm_db_version;
$wnm_db_version = "1.0";
function wnm_install(){
global $wpdb;
global $wnm_db_version;
$sql = "CREATE TABLE tbl_campaigns (
campaignID int(11) NOT NULL AUTO_INCREMENT,
campaign_name varchar(128) NOT NULL,
start_duration date NOT NULL,
end_duration date NOT NULL,
activity varchar(500) NOT NULL,
survey_settings varchar(50) NOT NULL,
limit varchar(50) NOT NULL,
goal varchar(100) DEFAULT NULL,
PRIMARY KEY (campaignID)
) ;";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
add_option("wnm_db_version", $wnm_db_version);
}
I just followed the instructions from this http://codex.wordpress.org/Creating_Tables_with_Plugins 我只是按照http://codex.wordpress.org/Creating_Tables_with_Plugins的说明进行操作
But it doesn't work. 但它不起作用。
What seems to be the problem with this code? 这段代码似乎有什么问题?
limit varchar(50) NOT NULL,
Limit is a keyword, change to something else like 限制是一个关键字,改为其他类似的东西
`limit` varchar(50) NOT NULL,
Use back ticks around keywords 在关键字周围使用后退标记
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.