docs for
原文链接:https://www.f2er.com/php/131530.htmlmulti_query
说:
Returns FALSE if the first statement Failed. To retrieve subsequent errors from other statements you have to call MysqLi_next_result() first.
Returns TRUE on success or FALSE on failure.
最后,文档中为multi_query发布的示例使用next_result的返回值来确定什么时候没有更多的查询;例如停止循环:
<?PHP $MysqLi = new MysqLi("localhost","my_user","my_password","world"); /* check connection */ if (MysqLi_connect_errno()) { printf("Connect Failed: %s\n",MysqLi_connect_error()); exit(); } $query = "SELECT CURRENT_USER();"; $query .= "SELECT Name FROM City ORDER BY ID LIMIT 20,5"; /* execute multi query */ if ($MysqLi->multi_query($query)) { do { /* store first result set */ if ($result = $MysqLi->store_result()) { while ($row = $result->fetch_row()) { printf("%s\n",$row[0]); } $result->free(); } /* print divider */ if ($MysqLi->more_results()) { printf("-----------------\n"); } } while ($MysqLi->next_result()); // <-- HERE! } /* close connection */ $MysqLi->close(); ?>
我不知道提供的查询的数量,也不知道我将要执行的sql的任何内容.因此,我不能仅仅将查询的数量与返回的结果数进行比较.但是,如果第三个查询是断开的查询,我想向用户显示错误消息.但是我似乎没有办法告诉next_result是否失败,因为没有更多的查询要执行,或者是因为sql语法中有错误.