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"] . "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.