我正在开发一个需要数据库交互性的wordpress插件。我在我的activate hook中使用dbDelta函数将几个表添加到数据库中。上周dbDelta
函数 正在运行,但是当我今天添加另一张表时,没有任何事情发生。我无法添加列或更改现有表的属性。有人建议在运行dbDelta之前拆分sql命令,但这也不起作用。
在您提出之前:是的,我已阅读了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
}
?>
答案 0 :(得分:0)
很抱歉这个混乱。几天前,我的托管服务改变了我们托管的服务器;我仍然登录到旧服务器来管理数据库。当我登录到正确的服务器时,更改已按预期进行。