Function name: mysqli_stmt::bind_result()
Applicable version: PHP 5 >= 5.3.0, PHP 7
Usage: This method is used to bind the query result to the specified variable so that the query result is obtained after the statement is executed.
Syntax: bool mysqli_stmt::bind_result ( mixed &$var1 [, mixed &$... ] )
parameter:
Return value: Return TRUE when successful, and FALSE when failure.
Example:
connect_errno) { echo "Failed to connect to MySQL: " . $mysqli->connect_error; exit(); } // Prepare the query statement $query = "SELECT name, age FROM users WHERE id = ?"; // Create preprocessing statement $stmt = $mysqli->prepare($query); // Bind parameter $id = 1; $stmt->bind_param("i", $id); // Execute query $stmt->execute(); // Bind result $stmt->bind_result($name, $age); // Get the result $stmt->fetch(); // Output the result echo "Name: " . $name . "In the example above, a database connection is first created. Then, a query statement is prepared and a preprocessing statement is created. Next, the query parameters are bound using the bind_param() method. Then, the query is executed and the query result is bound to the variables $name and $age using the bind_result() method. Finally, use the fetch() method to get the query result and output the result to the browser.
Note that the bind_result() method must be called after the statement is executed, otherwise the result will not be properly bound. In addition, the bound variable must be called before its value can be accessed.