0
我正在开发一个需要数据库交互性的wordpress插件。我正在使用我的激活挂钩中的dbDelta函数向数据库添加多个表。 dbDelta
函数上周工作时为,但是当我去添加另一个表格时,没有发生任何事情。我无法添加列或更改现有表的属性。有人建议在运行dbDelta之前分解sql命令,但这也不起作用。wordpress的dbDelta函数停止工作
之前你问:是的,我已经阅读了codex页面,并按照格式化说明。
下面是代码:
<?php
function install()
{
global $wpdb; //use the global variable wpdb, a class used to interact with wordpress's database
//define table names, using the the db's prefix
$gist_table = $wpdb->prefix . "cookbook_gist";
$tag_table = $wpdb->prefix . "cookbook_tags";
$tagKey_table = $wpdb->prefix . "cookbook_tagKeys";
$comment_table = $wpdb->prefix . "cookbook_comments";
$blacklist_table = $wpdb->prefix . "cookbook_blacklist";
//Include the wpdb function
require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); //the dbDelta function is in this file
//create the sql statements to add the tables
$sql = "CREATE TABLE $gist_table (
gist_id mediumint NOT NULL,
last_cached datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
last_updated datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
author tinytext NOT NULL,
description mediumtext NOT NULL,
header mediumtext NOT NULL,
body text NOT NULL,
footer mediumtext NOT NULL,
PRIMARY KEY (gist_id)
);";
//Actually add the table
dbDelta($sql);
$sql = "CREATE TABLE $tag_table (
tag_id mediumint NOT NULL AUTO_INCREMENT,
tag tinytext NOT NULL,
PRIMARY KEY (tag_id)
);";
dbDelta($sql);
$sql ="CREATE TABLE $tagKey_table (
id mediumint NOT NULL AUTO_INCREMENT,
gist_id mediumint NOT NULL,
tag_id mediumint NOT NULL,
PRIMARY KEY (id)
);";
dbDelta($sql);
$sql = "CREATE TABLE $comment_table (
id mediumint NOT NULL,
gist_id mediumint NOT NULL,
author tinytext NOT NULL,
date_created datetime NOT NULL,
comment mediumtext NOT NULL,
newcol text NOT NULL,
PRIMARY KEY (id)
);";
dbDelta($sql);
$sql = "CREATE TABLE $blacklist_table (
gist_id mediumint NOT NULL,
PRIMARY KEY (gist_id)
);";
dbDelta($sql); //makes the changes to the wp database
}
?>