MySQLi multi_query不会返回超过1个结果

问题描述 投票:0回答:1

当结果限制为1时,一切都很好。

但是,当我有超过1个结果时......它不会返回任何内容。

$output = $conn->multi_query("CALL `test_discount`('022979', 1101, 1, 'W', 100, @out); SELECT @out AS `discount`;");

if ($output == true){
    while($conn->next_result()){
        $result = $conn->store_result();
            while ($row = $result->fetch_assoc()){
                print_r($row);
                break;
            }                   
    if($conn->more_results() == false) { break; };
    }
}

我猜我做错了什么?

php mysql mysqli mysqli-multi-query multi-query
1个回答
1
投票

如果上面的SQL有意义,那么我建议首先获取过程返回的数据,然后选择那个stray @out变量。

$sql = "CALL `test_discount`('022979', 1101, 1, 'W', 100, @out)";
$res = $conn->multi_query($sql);
do {
    if ($res = $mysqli->store_result()) {
        foreach ($res as $row) {
            print_r($row);
        }
    }
} while ($mysqli->more_results() && $mysqli->next_result());

$out = $conn->query("SELECT @out")->fetch_row[0];
© www.soinside.com 2019 - 2024. All rights reserved.