我正在尝试使用以下代码从MySql存储过程中检索多个数据集,我收到错误
“调用未定义的函数mysqli_stmt_next_result”
我正在使用PHP版本5.6.2 使用MAMP(http://www.mamp.info/en/)
所有其他代码都有效,直到我尝试将第二个数据集添加到结果中。
感谢任何帮助,谢谢!
$mysql_host = "localhost";
$mysql_database = "dbname";
$mysql_user = "username";
$mysql_password = "password";
$link = mysqli_connect($mysql_host, $mysql_user, $mysql_password ,$mysql_database);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "CALL SprocName()";
if ($stmt = mysqli_prepare($link, $query)) {
mysqli_execute($stmt);
mysqli_stmt_bind_result($stmt, $ID);
$rtn = array();
while (mysqli_stmt_fetch($stmt)) {
$resultrow = (object) [
'ID' => $ID
];
array_push($rtn, $resultrow);
}
mysqli_stmt_next_result($stmt);
mysqli_stmt_bind_result($stmt, $ID);
$rtn2 = array();
while (mysqli_stmt_fetch($stmt)) {
$resultRow = (object) [
'ID' => $ID
];
array_push($rtn2, $resultRow);
}
echo json_encode(array('Result1' => $rtn, 'Result2' => $rtn2));
mysqli_stmt_close($stmt);
} else {
echo "Failed";
}
mysqli_close($link);