I am trying to update my plugin. Therefore, I have to update mysql_table. But when you try to create a new column, the program gets an exception.
This is my current 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);
Now I add colum to more than one table. I try to execute an Alter table, this works once and adds a column, but another update. I get this error.
This is mycode
$wpdb->query("ALTER TABLE wp_customer_say ADD say_state INT(1) NOT NULL DEFAULT 1");
And this is my mistake
WordPress database error: [Duplicate column name "say_state"] ALTER TABLE wp_customer_say ADD say_state INT (1) NOT NULL DEFAULT 1
I see this error and am not trying to do it;
$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;
and I get this error.
Warning: mysql_num_fields() expects parameter 1 to be resource, integer given in
Help me please. Thanks. Sorry bad english.