向wordpress数据库添加新列

 Mr-o蛋挞 发布于 2023-01-31 16:24

我尝试更新我的插件.所以我必须升级mysql_table.但是在尝试新列时,程序会获得异常.

这是我目前的表格:

$sql = "CREATE TABLE  {$table_name} (
        say_id             int(11)   not null AUTO_INCREMENT,
        customer_mail      text      not null,
        customer_name  text      not null,
        customer_messagge      text      not null,
        messagge_date_time  datetime  not null,

        PRIMARY KEY (say_id)
        )ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";

        require_once(ABSPATH . "wp-admin/includes/upgrade.php");
        dbDelta($sql);

现在我添加colum更多一个表.我尝试Alter表,这个工作一次并添加一个列但是再刷新一次我得到了这个错误.

这是我的代码

$wpdb->query("ALTER TABLE wp_customer_say ADD say_state INT(1) NOT NULL DEFAULT 1");

这是我的错误

WordPress数据库错误:[重复列名'say_state'] ALTER TABLE wp_customer_say ADD say_state INT(1)NOT NULL DEFAULT 1

我看到这个错误,我试试这个;

$query          = $wpdb->query("select * from wp_customer_say");
        $respond        = mysql_num_fields( $query );
        $column_array   = array();

        for($i = 0; $i < $respond ; $i++):
            $column_array[]     = mysql_field_name($query,$i);
        endfor;

        if( !in_array("say_state",$column_array) ):
            $wpdb->query("ALTER TABLE wp_customer_say ADD say_state INT(1) NOT NULL DEFAULT 1");
        endif;

我收到这个错误.

Warning: mysql_num_fields() expects parameter 1 to be resource, integer given in

请帮忙.谢谢.抱歉坏英语.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有