In PHP, while I try to use $mysqli->multi_query second time, it throws me following error.
I looked at MySQL manual, and similar questions asked at SO, all suggest using
either $mysqli->use_result();
or $mysqli->store_result();
or $mysqli->free_result();
.
But none solves the problem. Any idea what I might be missing.
Current output - 'Commands out of sync; you can't run this command now'
<?php
$link = mysqli_connect('localhost', 'root', '', 'database');
$array1 = array(1 => 1000, 2 => 1564, 3 => 2646, 4 => 5462, 5 => 8974);
$array2 = array(23 => 1975, 24 => 3789, 25 => 4658, 26 => 5978, 27 => 6879);
$update1 = '';
foreach($array1 as $k => $v) {
$update1 .= "UPDATE `ps_temp` SET `price` = {$v} WHERE `id` = {$k};";
}
$res = mysqli_multi_query($link, $update1); // Table is updated
$error = mysqli_error($link);
echo 'Error 1 - '.$error.'<hr>'; // Output : Error 1 -
$update2 = '';
foreach($array2 as $k => $v) {
$update2 .= "UPDATE `ps_temp2` SET `price` = {$v} WHERE `id` = {$k};";
}
mysqli_multi_query($link, $update2); // Table is not updated.
$error = mysqli_error($link);
echo 'Error 2 - '.$error.'<hr>'; // Output: Error 2 - 'Commands out of sync; you can't run this command now'
?>