Example of how to use bind_result vs get_result

The mysqli_stmt::bind_result() method binds variables to a prepared statement for result storage. The variables must be passed by reference. Here is an example of how to use bind_result():

<?php

$stmt = $mysqli->prepare("SELECT name, age FROM users WHERE id = ?");
$stmt->bind_param("i", $id);
$stmt->execute();
$stmt->bind_result($name, $age);
$stmt->fetch();
echo "Name: $name, Age: $age";
$stmt->close();

Watch a course Learn object oriented PHP

The mysqli_stmt::get_result() method is used to retrieve the result set from a prepared statement. The result set is returned as a mysqli_result object. Here is an example of how to use get_result():

<?php

$stmt = $mysqli->prepare("SELECT name, age FROM users WHERE id = ?");
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
  echo "Name: " . $row['name'] . ", Age: " . $row['age'] . "<br>";
}
$stmt->close();

Note that get_result() is available only with mysqlnd driver. If your PHP installation uses the libmysqlclient library, you can use mysqli_stmt_get_result() function instead.