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

mysqli_stmt::more_results

(mysqli_stmt_more_results) Check if multiple queries have more query results
Name:mysqli_stmt::more_results
Category:MySQLi
Programming Language:php
One-line Description:Check if there are more result sets available for querying

Function name: mysqli_stmt::more_results()

Applicable version: PHP 5 >= 5.3.0, PHP 7

Usage: the mysqli_stmt::more_results() function is used to check if there are more result sets available for querying.

Syntax: bool mysqli_stmt::more_results ( void )

Parameters: This function has no parameters.

Return value: Return true if more result sets are available, otherwise false.

Example:

 <?php // 创建数据库连接$mysqli = new mysqli("localhost", "username", "password", "database"); // 检查连接是否成功if ($mysqli->connect_errno) { echo "Failed to connect to MySQL: " . $mysqli->connect_error; exit(); } // 准备查询语句$query = "SELECT * FROM table1; SELECT * FROM table2;"; // 执行多结果集查询if ($mysqli->multi_query($query)) { do { // 获取当前结果集if ($result = $mysqli->store_result()) { // 处理当前结果集// 检查是否还有更多的结果集可用if ($mysqli->more_results()) { // 移动到下一个结果集$mysqli->next_result(); } else { // 没有更多结果集,退出循环break; } } } while ($mysqli->more_results()); } // 关闭数据库连接$mysqli->close(); ?>

In the example above, we first create a mysqli object and connect to the database. Then, we prepare a string containing multiple query statements. Next, we use the multi_query() function to perform multi-result set query. In the loop, we use the store_result() function to get the current result set, and after processing the current result set, we use the more_results() function to check if there are more result sets available. If so, we use the next_result() function to move to the next result set. When there are no more result sets, we exit the loop. Finally, we closed the database connection.

Note that before using the more_results() function, the store_result() function must be called to obtain the current result set. Furthermore, the function only makes sense in multi-result set queries.

Similar Functions
Popular Articles