Retrieving Multiple Result Sets with Stored Procedures in PHP/mysqli
In PHP/MySQLi, executing a stored procedure with multiple result sets requires careful handling. To advance to the second result set after executing the stored procedure, you must:
Here's an example code using PHP/MySQLi:
<code class="php">$stmt = mysqli_prepare($db, 'CALL multiples(?, ?)'); mysqli_stmt_bind_param($stmt, 'ii', $param1, $param2); mysqli_stmt_execute($stmt); // Fetch the first result set $result1 = mysqli_stmt_get_result($stmt); while ($row = $result1->fetch_assoc()) { printf("%d\n", $row['id']); } // Move to the second result set mysqli_stmt_next_result($stmt); $result2 = mysqli_stmt_get_result($stmt); while ($row = $result2->fetch_assoc()) { printf("%d\n", $row['id']); } mysqli_stmt_close($stmt);</code>
This code successfully retrieves and prints the data from both result sets in the specified stored procedure.
The above is the detailed content of How do you retrieve multiple result sets from a stored procedure in PHP/mysqli?. For more information, please follow other related articles on the PHP Chinese website!