Current Location: Home> Function Categories> mysqli_stmt::next_result

mysqli_stmt::next_result

(mysqli_stmt_next_result) Read the next result from multiple queries
Name:mysqli_stmt::next_result
Category:MySQLi
Programming Language:php
One-line Description:When executing stored procedures, move the pointer of the result set to the next result set

Function name: mysqli_stmt::next_result()

Applicable version: PHP 5 >= 5.3.0, PHP 7

Function description: mysqli_stmt::next_result() is used to move the pointer of the result set to the next result set when executing a stored procedure.

Syntax: bool mysqli_stmt::next_result()

Parameter Description: This function has no parameters.

Return value: Returns true if moved to the next result set successfully. If no more result sets are available, false is returned.

Sample code:

 <?php // 创建数据库连接$mysqli = new mysqli("localhost", "username", "password", "database"); // 检查连接是否成功if ($mysqli->connect_errno) { echo "连接数据库失败: " . $mysqli->connect_error; exit(); } // 准备执行存储过程$stmt = $mysqli->prepare("CALL your_stored_procedure()"); // 执行存储过程if ($stmt->execute()) { // 检查是否有结果集if ($stmt->store_result()) { // 处理第一个结果集// ... // 检查是否还有更多的结果集while ($stmt->next_result()) { // 处理下一个结果集// ... } } else { echo "没有结果集可用"; } } else { echo "执行存储过程失败: " . $stmt->error; } // 关闭语句和数据库连接$stmt->close(); $mysqli->close(); ?>

In the example code above, we first create a database connection and then prepare to execute a stored procedure. After executing the stored procedure, we use store_result() method to check if a result set is available. If there is a result set, the first result set is processed and next_result() method is used to process the subsequent result set in the loop. If no result set is available, the corresponding error message is output. Finally, we closed the statement and database connection.

Similar Functions
Popular Articles