【问题标题】:Mysqli can't execute 2 query on the same connectionMysqli 不能在同一个连接上执行 2 个查询
【发布时间】:2015-04-03 16:42:47
【问题描述】:

我必须使用相同的 mysqli 连接执行 2 个不同的查询。 我尝试在以下代码中使用 multi_query($query):

<?php 
$re = $mysqli->query("SET CHARACTER SET 'utf8'");
$query = "CALL LDmodel_tree();CALL LDmodel_file()";
$mysqli->multi_query($query);

echo 'var fold = [];'."\n";
echo 'var file = [];'."\n";


$result = $mysqli->store_result();
while ($rsto = $result->fetch_row()) 
        {
        $y=0;$cart = array ();
        do {$cart[$x][$y] = $rsto[$y]; $y++; } while ($y<4);
        echo 'fold['.$x.'] = ['.$cart[$x][3].',"'.$cart[$x][1].'",'.$cart[$x][0].','.$cart[$x][2].'];'."\n";        /* ID, nome, livello, madre */
        $x++;
        }          

$result->free();
echo 'var n_cart='.$x.';'."\n";


$result = $mysqli->next_result();
while ($rsto = $result->fetch_row())
        {
        $y=0;$cart = array ();
        do {$cart[$x][$y] = $rsto[$y]; $y++; } while ($y<6);
        echo 'file['.$x.'] = ['.$cart[$x][0].',"'.$cart[$x][1].'","'.$cart[$x][2].'",'.$cart[$x][3].','.$cart[$x][4].','.$cart[$x][5].'];'."\n";
        $x++;
        }          
$result->free();
echo 'var n_file='.$nx.';'."\n";
?>

在第一次查询之后,它会触发这个错误:

在第 25 行的 E:\EasyPHP-5.3.9\www\MOD_tree.php 中调用非对象的成员函数 fetch_row()

请帮忙!!!

【问题讨论】:

    标签: php mysqli


    【解决方案1】:

    mysqli::next_result() 返回一个布尔值。使用mysqli::store_result() 检索下一个结果。

    https://php.net/manual/en/mysqli.next-result.php

    【讨论】:

    • 代码更改:$result = $mysqli->store_result(); while ($rsto = $result->fetch_row()) { ...... } $result->free();但没有任何改进。我需要添加“more_result”语句吗?
    • 这是否回答了您的问题?如果是这样,您可以通过单击左侧的链接来​​接受此答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-16
    • 1970-01-01
    • 1970-01-01
    • 2013-07-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多