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

来源:互联网 发布:好一点的男装淘宝店铺 编辑:程序博客网 时间:2024/06/07 10:33

搞了一个下午,原来是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());

?>


原创粉丝点击