This question already has an answer here:
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
If you are using Virtual Private Server
Go to this directory /var/cpanel/easy/apache/rawopts
And create a new file all_php5 [/var/cpanel/easy/apache/rawopts]# cat > all_php5
add below text and close the file
--with-mysqli=mysql
Go Easy Apache v3.32.14 in WHM Customize basic profile and enable MySQL "Improved" extension in Exhaustive Options List and build.
As stated, make sure mysqlnd is installed.
I have just spent an hour scouring all the answers on StackOverflow sorting this out because I missed out a vital step and my scripts still failed - the step was restarting the httpd daemon.
uninstall php-mysql install php-mysqlnd
For me, running Centos 5.6 and php55, this was a case of
yum remove -y php55w-mysql yum install -y php55w-mysqlnd
This all went perfectly but still my PHP was failing with the error "Call to undefined method mysqli_stmt::get_result"
So I restarted Apache
service httpd restart
and - TA-DA - it worked perfectly.
This is too long for a comment.
Try this:
Now, if
while ( $statement-> fetch() )
doesn't work quite like you want it to, try replacing it withwhile ( $statement-> fetch_assoc() )
, the way you have it now.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.