脚本宝典收集整理的这篇文章主要介绍了php – 如何确保我捕获了MySQLi :: multi_query中的所有错误?,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
multi_query
说:
最后,文档中为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语法中有错误.
if ($MysqLi->multi_query(...)) { do { // fetch results if (!$MysqLi->more_results()) { break; } if (!$MysqLi->next_result()) { // report error break; } } while (true); }
以上是脚本宝典为你收集整理的php – 如何确保我捕获了MySQLi :: multi_query中的所有错误?全部内容,希望文章能够帮你解决php – 如何确保我捕获了MySQLi :: multi_query中的所有错误?所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。