Php MySQLi multi_查询不会返回超过1个结果
当结果限制为1时,一切都很好 但是,当我有超过1个结果时…它不会返回任何结果Php MySQLi multi_查询不会返回超过1个结果,php,mysql,mysqli,mysqli-multi-query,multi-query,Php,Mysql,Mysqli,Mysqli Multi Query,Multi Query,当结果限制为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->stor
$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; };
}
}
我猜我做错了什么吗?如果上面的SQL有任何意义,那么我建议先获取过程返回的数据,然后选择那个游离的@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];
break
语句在第一行之后停止循环。摆脱它。你不需要更多结果()
检查。当结果用完时,next\u result()
将返回false
@Barmar这不是问题所在。已删除break
,但仍不返回任何内容more_results()
现在也被禁用,并且它仍然不会返回任何内容。您希望得到什么结果SELECT@out
只能返回一个值。如果您的代码应该返回多个结果集/多行,那么您应该首先处理SQL,而不是从PHP开始