Reputation: 37
I'm trying to replace words in more tables on WordPress, to be more efficient I made a list of update queries and want to run them all at once but for some reason it says :
*WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'UPDATE dev_options SET option_value = REPLACE(option_value, 'Red', 'Blue')' at line 2]
UPDATE dev_options SET option_value = REPLACE(option_value, 'Red', 'Blue'); UPDATE dev_options SET option_value = REPLACE(option_value, 'Red', 'Blue');*
The code:
global $wpdb;
echo $wpdb->query("
UPDATE dev_options SET option_value = REPLACE(option_value, 'Red', 'Blue');
UPDATE dev_options SET option_value = REPLACE(option_value, 'Red', 'Blue');
");
If I delete the second query it runs as expected. Is there something I'm missing here?
Upvotes: 1
Views: 1109
Reputation: 43
Use another DB adapter or extension. In most cases, if you need to run migrations, such as create tables and insert many rows, it's not a problem if you don't use wpdb (and thus have to create another DB connection), because this is only going to happen very rarely. Also, due to the crazy transformations done by dbDelta(), it's probably more reliable to find a way to run raw queries.
mysqli_multi_query() is a function of the mysqli (not outdated) extension that can easily run multiple statements at once. PDO can run multiple queries in emulation mode.
Upvotes: 1