【发布时间】:2017-09-22 00:44:39
【问题描述】:
我正在尝试在 PHP 中循环通过预准备语句调用的存储过程。希望这不是不可能的。这是我的 PHP 代码:
$database = new mysqli($server, $user, $pass, $db);
$stmt = $database->prepare("CALL thisShouldReturnEightResultSets (?)");
$stmt->bind_param("i", $id);
$stmt->execute();
do {
if ($res = $stmt->bind_result($myvar)) {
$stmt->fetch();
echo "*" . $myvar . "<br/>";
} else {
if ($stmt->errno) {
echo "Store failed: (" . $stmt->errno . ") " . $stmt->error;
}
}
} while ($stmt->next_result());
应该这样打印:
* 4
* 16
* 7
etc...
... 然后在结果集用完后退出。相反,我得到:
* 4
Fatal error: Call to undefined method mysqli_stmt::next_result()
起初我尝试了 get_result 而不是 bind_result,但是出错了。基于this我发现我没有安装mysqlnd驱动。我用 bind_result 解决了这个问题。现在我需要解决 next_result 的问题,我猜这也是 mysqlnd 驱动程序的一部分。我在这里有什么选择?技术说明:
PHP Version 5.3.2-1ubuntu4.11
谢谢。
【问题讨论】:
-
next_result仅在使用multi_query时使用。 -
你没有执行多个查询,为什么你认为你需要使用
next_result? -
存储过程中有多个选择。
标签: php mysqli prepared-statement multiple-resultsets