2012-07-09 139 views
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  
} 

?> 

回答

0

很抱歉的混亂。幾天前我的託管服務改變了我們託管的服務器;我仍然登錄到舊的服務器來管理數據庫。當我登錄到正確的服務器時,更改已按預期進行。