$ db_name = $ wpdb-> prefix。' demo1';
function install_plugin() {
global $wpdb;
global $db_name;
$sql="CREATE TABLE".$db_name."(
`id` int(9) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL
);";
require_once(ABSPATH.'wp-admin/includes/upgrade.php');
dbDelta($sql);
}
register_activation_hook(文件下,' install_plugin&#39);
答案 0 :(得分:0)
因为您的create table语法错误:
表定义不正确;只能有一个自动列,必须将其定义为键
尝试以下
CREATE TABLE ".$db_name."(
`id` int(9) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
);