用多查询时mysqli::next_result()出错

本文探讨了在不同PHP版本下执行数据库操作时遇到的问题,特别是使用`mysqli::next_result()`函数在PHP 5.3.x版本中引发的错误。通过引入条件判断,确保循环只迭代有效结果集,最终解决了错误并提供了跨版本兼容性的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

搞了一个下午,原来是PHP版本的问题


用HTTP测试时PHP版本是5.4.x,正常执行,而用IDC单元phpunit测试时是版本是5.3.x,导至出现错误

mysqli::next_result(): There is no next result set. Please, call mysqli_more_results()/mysqli::more_results() to check whether to call this function/method

我写的是:

do{.......}while($link->next_result());

在php5.3.x中出错,在5.4.x中正常

后改为以下这样就正常了

while ($mysqli->more_results()){
    $mysqli->next_result();
}




以下是老外的解决办法

if you don't iterate through all results you get "server has gone away" error message ...

to resolve this, in php 5.2 it is enough to use

<?php
  
// ok for php 5.2
  
while ($mysqli->next_result());
?>

to drop unwanted results, but in php 5.3 using only this throws

mysqli::next_result(): There is no next result set. Please, call mysqli_more_results()/mysqli::more_results() to check whether to call this function/method

so it should be replaced with

<?php
  
// ok for php 5.3
  
while ($mysqli->more_results() && $mysqli->next_result());
?>

I also tried but failed:

<?php

  
// can create infinite look in some cases
  
while ($mysqli->more_results())
    
$mysqli->next_result();

  
// also throws error in some cases
  
if ($mysqli->more_results())
    while (
$mysqli->next_result());

?>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值