0

我正在开发一个需要数据库交互性的 wordpress 插件。我在我的激活钩子中使用 dbDelta 函数将几个表添加到数据库中。该dbDelta功能上周工作,但是当我今天去添加另一个表时,什么也没发生我也无法添加列或更改现有表的属性。有人建议在运行 dbDelta 之前分解 sql 命令,但这也不起作用。

在你问之前:是的,我已经阅读了法典页面并遵循了格式说明。

这是代码:

<?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    
}

?>
4

1 回答 1

0

对困惑感到抱歉。几天前,我的托管服务更改了我们托管的服务器;我仍在登录旧服务器来管理数据库。当我登录到正确的服务器时,更改已按预期进行。

于 2012-07-10T12:59:30.010 回答