正如标题所说,我有一个问题。我的插件在激活时不会创建自定义表。我的代码是:
function bsp_create_update_table()
{
global $wpdb; //geting the acces to a wp tables
$tablename=$wpdb->prefix . "students"; //the name of a table with it\'s prefix
//checking if the table with the name we created a line above exists
if($wpdb->get_var("SHOW TABLES LIKE \'$tablename\'") != $tablename)
{
//if it does not exists we create the table
$sql="CREATE TABLE `$tablename`(
`students_id` INT(11) NOT NULL AUTO_INCREMENT,
`students_name` VARCHAR (50) NOT NULL,
`students_lastname` VARCHAR (50) NOT NULL,
`students_email` VARCHAR 850) NOT NULL,
`students_course` VARCHAR (100) NOT NULL,
`students_date` DATETIME,
PRIMARY KEY (students_id)
);";
//wordpress function for updating the table
require_once(ABSPATH . \'wp-admin/includes/upgrade.php\');
dbDelta($sql);
}
}
我有一个这样的钩子:
register_activation_hook(__FILE__, \'bsp_create_update_table\');
当插件被激活时,并没有创建任何表,我只是不知道为什么。有什么想法吗?