mysqli_result::free
(mysqli_free_result) Release the memory related to the result
Function name: mysqli_result::free()
Applicable version: PHP 5, PHP 7
Function description: mysqli_result::free() is used to free memory resources related to the result set.
Syntax: bool mysqli_result::free ( void )
parameter:
Return value:
Example:
<?php // 与数据库建立连接$mysqli = new mysqli("localhost", "username", "password", "database"); // 检查连接是否成功if ($mysqli->connect_errno) { echo "数据库连接失败:" . $mysqli->connect_error; exit(); } // 执行查询语句$query = "SELECT * FROM users"; $result = $mysqli->query($query); // 检查查询结果是否为空if ($result->num_rows > 0) { // 输出每一行数据while ($row = $result->fetch_assoc()) { echo "ID: " . $row["id"] . ", Name: " . $row["name"] . "<br>"; } } else { echo "查询结果为空"; } // 释放结果集相关的内存资源$result->free(); // 关闭数据库连接$mysqli->close(); ?>
In the example above, we first establish a connection to the database and execute a query statement. Then, the memory resources related to the result set are released by calling the mysqli_result::free() function. Finally, close the database connection. This ensures timely release of memory resources and improves program performance and efficiency.