rksh rksh - 5 months ago 8
PHP Question

Fatal error: Call to undefined method mysqli_stmt::get_result()

My following php MYSQLi is not working, PHP version 5.9

$query = $conn->prepare("SELECT * FROM users WHERE token= ? LIMIT 1");
$query->bind_param('s',$cvalue);
$query->execute();
$result = $query->get_result();
$row = $result->fetch_assoc();


It's giving me the following error, Fatal error: Call to undefined method mysqli_stmt::get_result()

Where is the error? How can I fix it? Thanks

Answer

This is too long for a comment.

Try this:

if($statement=$conn->prepare("SELECT * FROM users WHERE token= ? LIMIT 1")){

$statement-> bind_param('s',$cvalue);

// Execute
 $statement-> execute();

// Bind results
 $statement-> bind_result($token);

// Fetch value
 while ( $statement-> fetch() ) {
 echo $token . "<br>";
 }

// Close statement
 $statement-> close();
 }

// Close entire connection
 $conn-> close();

Now, if while ( $statement-> fetch() ) doesn't work quite like you want it to, try replacing it with while ( $statement-> fetch_assoc() ), the way you have it now.

  • N.B.: If this doesn't work for you, I will simply delete the answer.

Footnotes:

As Rocket Hazmat stated in a comment, and I quote: It requires both PHP 5.3+ and the mysqlnd driver.

So, make sure that the driver is installed.

Comments