Home > Backend Development > PHP Tutorial > Why am I getting a 'Call to undefined method mysqli_stmt::get_result()' error?

Why am I getting a 'Call to undefined method mysqli_stmt::get_result()' error?

Mary-Kate Olsen
Release: 2024-12-26 10:42:15
Original
621 people have browsed it

Why am I getting a

"mysqli_stmt::get_result()" method call undefined issue

While trying to use "get_result()" method from "mysqli_stmt" When obtaining query results in the object, "Call undefined method" appears. mysqli_stmt::get_result()" error.

Cause of the problem:

The error indicates that the "get_result()" method is not available for the "mysqli_stmt" object. This may be caused by missing "mysqlnd" driver.

Solution:

  1. Install mysqlnd driver:

    This driver is useful for using " get_result()" method is crucial. Please make sure it is installed on your web space.

  2. Use bind_result() and fetch():

    If you cannot install the "mysqlnd" driver, you can use "bind_result() ” and “fetch()” methods to obtain query results. These methods are not affected by the "mysqlnd" driver. The sample code is as follows:

$stmt->bind_result($emailVerified, $blocked);
$stmt->fetch();
Copy after login
  1. Check mysqli_stmt->execute() Return value:

    Ensure that the "mysqli_stmt->execute()" method has been successfully executed. If it returns "false", no result will be set for the "stmt" object.

Example:

Here is the modified code that has solved the problem:

include 'conn.php';
$conn = new Connection();
$query = 'SELECT EmailVerified, Blocked FROM users WHERE Email = ? AND SLA = ? AND `Password` = ?';
$stmt = $conn->mysqli->prepare($query);
$stmt->bind_param('sss', $_POST['EmailID'], $_POST['SLA'], $_POST['Password']);

if ($stmt->execute()) {
    $stmt->bind_result($emailVerified, $blocked);
    $stmt->fetch();
    // Use $emailVerified and $blocked here...
} else {
    echo "Error executing statement: " . $stmt->error;
}
Copy after login

The above is the detailed content of Why am I getting a 'Call to undefined method mysqli_stmt::get_result()' error?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template