在php中调用存储过程(返回两个表)


Call Stored procedure (which returns two table) in php

我正在使用php开发GUI工具。数据库中已经存在存储过程。这些存储过程不能更改。(其他工具依赖).

我的问题:有一个过程,其中返回两个表在mysql中直接调用。(可能是2 select语句在里面)。

我如何使用'mysqli——php'来显示从两个表返回的数据?

说明:返回的两个表中有相同的列(name,id,status)

使用mysqli::use_result

$mysqli = new mysqli("localhost", "root", "password", "db_name");
if ($mysqli->connect_errno) {
    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") ";
}
$query = "CALL sp_multiple results (?, ?)";
$stmt = $mysqli->prepare($query);
if (!$stmt) {
    echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
$stmt->bind_param("ss", $param1, $param2);
$stmt->execute();
/* get first result set */
if ($result1 = $mysqli->use_result()) {
    //fetch data
    $result1->close();
}
/* get second result set */
if ($result2 = $mysqli->use_result()) {
    //fetch data
    $result2->close();
}
$mysqli->close();