Function name: mysqli_stmt::close()
Applicable version: PHP 5, PHP 7
Usage: This function is used to close the preprocessing statement object and release the resources associated with it.
Syntax: bool mysqli_stmt::close()
Parameters: None
Return value: Returns true if the preprocessing statement object is successfully closed. If an error occurs, false is returned.
Example:
connect_errno) { echo "Failed to connect to the database: " . $mysqli->connect_error; exit(); } // Prepare the preprocessing statement $stmt = $mysqli->prepare("SELECT * FROM users WHERE age > ?"); // Binding parameter $age = 18; $stmt->bind_param("i", $age); // Execute query $stmt->execute(); // Get the result $result = $stmt->get_result(); // Output result while ($row = $result->fetch_assoc()) { echo $row["name"] . "In the example above, we first create a database connection $mysqli. Then, we prepare a preprocessing statement $stmt and bind a parameter $age. Next, we execute the query and get the result $result. After processing the result, we first close the result set $result, and then close the preprocessing statement object $stmt. Finally, we closed the database connection $mysqli.
Note that closing preprocessing statement objects is a good programming habit to ensure that the resources associated with them are released in a timely manner and avoid memory leaks and performance issues.