Current Location: Home> Function Categories> mysqli::store_result

mysqli::store_result

(mysqli_store_result) Transfer result set from the previous query
Name:mysqli::store_result
Category:MySQLi
Programming Language:php
One-line Description:Save the query results in a buffer for subsequent operations

Function name: mysqli::store_result()

Applicable version: PHP 5, PHP 7

Function description: The mysqli::store_result() function is used to save query results in a buffer for subsequent operations.

Syntax: mysqli::store_result()

Return value: Return TRUE if successful, otherwise return FALSE.

Example:

 <?php // 连接到数据库$mysqli = new mysqli("localhost", "username", "password", "database"); // 检查连接是否成功if ($mysqli->connect_errno) { echo "连接失败:" . $mysqli->connect_error; exit(); } // 执行查询语句$result = $mysqli->query("SELECT * FROM users"); // 检查查询是否成功if (!$result) { echo "查询失败:" . $mysqli->error; exit(); } // 将查询结果保存在缓冲区中$mysqli->store_result(); // 获取查询结果的行数$num_rows = $result->num_rows; echo "查询结果有" . $num_rows . " 行数据"; // 释放查询结果$result->free(); // 关闭数据库连接$mysqli->close(); ?>

In the above example, we first execute a query using the mysqli::query() function, and then use the mysqli::store_result() function to save the query results in a buffer. Next, we use the mysqli_result::num_rows property to get the number of rows of the query result and output it to the screen. Finally, we released the query result and closed the database connection.

Note that after using the mysqli::store_result() function, the query results must be released through the mysqli_result::free() function to avoid memory leaks.

Similar Functions
Popular Articles