我尝试更新我的插件.所以我必须升级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
请帮忙.谢谢.抱歉坏英语.