在mysqli ::
query中,如果您使用MYSQLI_USE_RESULT,则所有后续调用都将返回错误命令,除非您调用mysqli_free_result()
调用多个存储过程时,可能会遇到以下错误:“命令不同步;您现在不能运行此命令”。即使在两次调用之间对结果对象使用close()函数,也会发生这种情况。要解决此问题,请记住在每次存储过程调用之后在mysqli对象上调用next_result()函数。请参见下面的示例:
<?php// New Connection$db = new mysqli('localhost','user','pass','database');// Check for errorsif(mysqli_connect_errno()){ echo mysqli_connect_error();}// 1st Query$result = $db->query("call getUsers()");if($result){ // Cycle through results while ($row = $result->fetch_object()){ $user_arr[] = $row; } // Free result set $result->close(); $db->next_result();}// 2nd Query$result = $db->query("call getGroups()");if($result){ // Cycle through results while ($row = $result->fetch_object()){ $group_arr[] = $row; } // Free result set $result->close(); $db->next_result();}else echo($db->error);// Close connection$db->close();?>我希望这个能帮上忙



