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

mysqli_stmt::free_result

(mysqli_stmt_free_result) Release the memory of the storage result of the given statement handle.
Name:mysqli_stmt::free_result
Category:MySQLi
Programming Language:php
One-line Description:Release the result set related to preprocessing statements

Function name: mysqli_stmt::free_result()

Function Description: This function is used to release the result set related to the preprocessing statement.

Applicable version: PHP 5, PHP 7

Syntax: mysqli_stmt::free_result()

Parameters: No parameters.

Return value: This function does not return value.

Example:

 <?php // 创建数据库连接$mysqli = new mysqli("localhost", "username", "password", "database"); // 检查连接是否成功if ($mysqli->connect_error) { die("连接失败: " . $mysqli->connect_error); } // 准备预处理语句$stmt = $mysqli->prepare("SELECT id, name FROM users WHERE age > ?"); // 绑定参数$age = 18; $stmt->bind_param("i", $age); // 执行查询$stmt->execute(); // 绑定结果$stmt->bind_result($id, $name); // 输出结果while ($stmt->fetch()) { echo "ID: " . $id . ", Name: " . $name . "<br>"; } // 释放结果集$stmt->free_result(); // 关闭预处理语句和数据库连接$stmt->close(); $mysqli->close(); ?>

illustrate:

  1. First, we create a mysqli object to connect to the database.
  2. Then, prepare a preprocessing statement containing a parameter placeholder.
  3. Use bind_param() function to bind parameters, here we set the age to 18.
  4. Execute the query statement and bind the result to the variables $id and $name.
  5. Use while loop to iterate through the result set and output the ID and Name of each record.
  6. Finally, use the free_result() function to release the result set.
  7. Use the close() function to close the preprocessing statement and database connection.
Similar Functions
Popular Articles