【发布时间】:2014-02-15 08:16:01
【问题描述】:
我正在尝试更新我的插件。所以我必须升级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);
现在我在一张表中添加了更多列。我尝试使用 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 添加 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
请帮忙。谢谢你。 抱歉英语不好。
【问题讨论】:
-
这是因为您的数据库执行其设计目的...持久性