When calling multiple stored procedures, you can run into the following error: "Commands out of sync; you can't run this command now".
This can happen even when using the close() function on the result object between calls.
To fix the problem, remember to call the next_result() function on the mysqli object after each stored procedure call. See example below:
<?php
$db = new mysqli('localhost','user','pass','database');
if(mysqli_connect_errno()){
echo mysqli_connect_error();
}
$result = $db->query("call getUsers()");
if($result){
while ($row = $result->fetch_object()){
$user_arr[] = $row;
}
$result->close();
$db->next_result();
}
$result = $db->query("call getGroups()");
if($result){
while ($row = $result->fetch_object()){
$group_arr[] = $row;
}
$result->close();
$db->next_result();
}
else echo($db->error);
$db->close();
?>