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

mysqli_stmt::reset

(mysqli_stmt_reset)Reset Preparation Statement
Name:mysqli_stmt::reset
Category:MySQLi
Programming Language:php
One-line Description:Reset the status of the mysqli_stmt object so that the prepared statement is reexecute

Function name: mysqli_stmt::reset()

Function Description: This function is used to reset the state of the mysqli_stmt object to re-execute the prepared statement.

Applicable version: PHP 5 >= 5.3.0, PHP 7

Syntax: bool mysqli_stmt::reset()

Parameters: None

Return value: Return true if reset is successful; otherwise return false.

Example:

<?php // 创建数据库连接 $conn = new mysqli("localhost", "username", "password", "database"); // 检查连接是否成功 if ($conn---> connect_error) { die("Connection failed: " . $conn->connect_error); } // Prepare SQL statement $sql = "SELECT * FROM users WHERE age > ?"; // Create preprocessing statement object $stmt = $conn->prepare($sql); // Bind parameter $stmt->bind_param("i", $age); // Set parameter value $age = 20; // Execute query $stmt->execute(); // Get result set $result = $stmt->get_result(); // Output result while ($row = $result->fetch_assoc()) { echo "ID: " . $row["id"] . ", Name: " . $row["name"] . ", Age: " . $row["age"] . "
"; } // Reset the state of the mysqli_stmt object $stmt->reset(); // Reset the parameter value $age = 30; // Execute the query again $stmt->execute(); // Get the result set $result = $stmt->get_result(); // Output the result while ($row = $result->fetch_assoc()) { echo "ID: " . $row["id"] . ", Name: " . $row["name"] . ", Age: " . $row["age"] . "
"; } // Close the preprocessing statement object $stmt->close(); // Close the database connection $conn->close(); ?>

In the example above, we first create a mysqli connection object $conn. Then, we prepare a SELECT statement and create a mysqli_stmt object $stmt to execute the statement. We bind a parameter $age through the bind_param() function. Next, we execute the first query and output the result. Then, we reset the state of the $stmt object using the reset() function and reset the parameter value $age. Finally, we execute the query again and output the result.

Note that the reset() function will only reset the state of the mysqli_stmt object and will not close or destroy the object. If you want to completely destroy the mysqli_stmt object, you can use the close() function.

Similar Functions
Popular Articles