To manage database plugin update, I changed my code using dbDelta
.
old code
myfunction(){
...
$query_string = "INSERT INTO {$table_name} {$str_column_names} VALUES {$str_values}";
$is_data_inserted = $wpdb->query( $query_string );
if( !$is_data_inserted ){
$message_error = sprintf( "impossible to insert the data %s for the table %s!",
serialize( $data_item_attrs ),
$table_name
);
$wpdb->show_errors();
wp_error_log( $message_error, "Insert Data Error" );
return false;
}
return true;
}
new code
myfunction(){
...
$query_string = "INSERT INTO {$table_name} {$str_column_names} VALUES {$str_values}";
dbDelta( $query_string );
}
My problem is using dbDelta
disturbs inserts containing the character ";".
It´s because in dbDelta
, there is ";" as delimiter.
How can I fix this ?
dbDelta
for inserting data? That's not what it's for. It's intended for creating and modifying tabes. To insert data use$wdb->insert()
.