Fatal error: Call to undefined method mysqli_stmt :: get_result ()
My next 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();
This gives me the following error:
Fatal error: Call to undefined method mysqli_stmt :: get_result ()
Where is the mistake? How can I fix this? Thanks to
source to share
It's too long for a comment.
Try the following:
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 it while ( $statement-> fetch() )
doesn't work the way you want it, try replacing it while ( $statement-> fetch_assoc() )
with what you have.
- NB: If that doesn't work for you, I'll just delete the answer.
Footnote:
As Rocket Hazmat said in a comment and I am quoting: this requires both PHP 5.3+ and the mysqlnd driver.
So, make sure the driver is installed.
source to share
As stated, make sure mysqlnd is installed.
I just spent an hour clearing all the answers on StackOverflow sorting this because I missed an important step and my scripts still failed - the httpd daemon was restarted at this point.
remove php-mysql install php-mysqlnd
For me, working with Centos 5.6 and php55, this was the case
yum remove -y php55w-mysql yum install -y php55w-mysqlnd
Everything went fine, but still my PHP didn't fail with the error "Calling undefined method mysqli_stmt :: get_result"
So I restarted Apache
httpd restart service
and - TA-DA - it worked great.
source to share
If you are using Virtual Private Server
-
Go to this directory / var / cpanel / light / apache / rawopts
-
And create a new file all_php5 [/ var / cpanel / easy / apache / rawopts] # ββcat> all_php5
-
add below text and close file
--with-MySQLi = MySQL -
Go Easy Apache v3.32.14 in WHM Set up a base profile and enable the "Enhanced" MySQL extension in the "Exhaustive list of options" and build.
source to share