mysql_multi_query problem!

This is driving me nuts. I’ve decided to try and implement mysqli_multi_query into a script I’m currently working on to reduce the number of mysqli_query calls. I’m encountering a really odd problem. After I call the mysql_multi_query function and run a bunch of queries (all goes well), all my normal queries after that are screwed. They all turn into booleans.

For example, this piece of code works fine…

1:$category_list_query = mysqli_query($mysql, "SELECT * FROM categories ORDER BY cat_order ASC");
2:while($category_list = mysqli_fetch_array($category_list_query)){
3:// do something here

But If I add mysqli_multi_query to the top of that like so…

1: mysqli_multi_query($mysql, "DELETE FROM cart WHERE id = '800'; DELETE FROM cart WHERE id = '800'");
3: $category_list_query = mysqli_query($mysql, "SELECT * FROM categories ORDER BY cat_order ASC");
4: while($category_list = mysqli_fetch_array($category_list_query)){
5: // do something here
6: }

I get errors that look like this…

mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in D:\…\…\… on line 4

It’s like the mysqli_multi_query stuffs up all the other queries in the script. I don’t know why this is either. I’ve stored the results of mysqli_multi_query with and without a variable and nothing seems to fix it. Can anyone offer any help?


MySQL couldn’t execute your query, are you sure that commenting the first statement removes the problem?

Yes, I’m sure. My shopping-cart.php page was fine until I added that mysqli_multi_query. I thought that maybe something in my script was causing the problem, so I wrote a really small script (like the example above) and of course, I got the same problem. Here’s the script. It works fine when I comment out the multi_query.

$mysql_server = "localhost";
$mysql_username = "root";
$mysql_password = "";
$mysql_database = "test";
$mysql = mysqli_connect($mysql_server, $mysql_username, $mysql_password, $mysql_database);
// This query doesn't do anything as there are no items in the cart with a quantity that high. But it doesn't matter if the query succeeds or fails.
$update_cart_items = mysqli_multi_query($mysql, "DELETE FROM cart WHERE quantity = '800'; DELETE FROM cart WHERE quantity = '700';") or die(mysqli_error());

$category_list_query = mysqli_query($mysql, "SELECT * FROM categories ORDER BY cat_order ASC");
while($category_list = mysqli_fetch_array($category_list_query)){
	echo $category_list['cat_id'];

What’s even more odd is that if I refresh heaps of times in my browser, the script will sometimes work without getting that error. This is just so odd. Can someone please slightly modify the script posted above (just modify the database data) and let me not of your results. I have no idea what is going on. The way that it sometimes works and sometimes doesn’t really makes me confused. A bad php install maybe? it’s been working fine though. I’ve disabled the one plugin I recently installed and so I don’t think it would be that.

Any help will be hugely appreciated.

Does anyone have any idea of why this is happening? Do I have to somehow clear the results of the multi query before I can perform an ordinary query?