Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call to undefined method mysqli_stmt::get_result() AND mysqlnd installed

Tags:

php

mysqli

As the title suggests, I have mysqlnd available on my shared hosting server running PHP version 5.4. When I attempt to call the mysqli get_result() function, I get this error.

I have spoken several times with the hosting provider, and most recently they told me to try running

# /opt/ntphp/php54/bin/php -i | grep -i mysqlnd

I hopped on ssh and ran this command which gave this:

mysqlnd
mysqlnd => enabled
Version => mysqlnd 5.0.10 - 20111026 - $Id: c85105d7c6f7d70d609bb4c000257868a40840ab $
Loaded plugins => mysqlnd,example,debug_trace,auth_plugin_mysql_native_password,auth_plugin_mysql_clear_password
mysqlnd statistics =>  
Client API version => mysqlnd 5.0.10 - 20111026 - $Id: c85105d7c6f7d70d609bb4c000257868a40840ab $

So, that appears to me as I would expect.

I found another piece of PHP code on another forum post that suggests running:

$hasMySQL = false; $hasMySQLi = false; $withMySQLnd = false; $sentence = '';

if (function_exists('mysql_connect')) {
    $hasMySQL = true;
    $sentence.= "(Deprecated) MySQL <b>is installed</b> "; } else
    $sentence.= "(Deprecated) MySQL <b>is not</b> installed ";

if (function_exists('mysqli_connect')) {
     $hasMySQLi = true;
     $sentence.= "and the new (improved) MySQL <b>is installed</b>. "; } else
     $sentence.= "and the new (improved) MySQL <b>is not installed</b>. ";

 if (function_exists('mysqli_get_client_stats')) {
     $withMySQLnd = true;
     $sentence.= "This server is using MySQLnd as the driver."; } else
     $sentence.= "This server is using libmysqlclient as the driver.";

 echo $sentence;

I did this and got the result:

(Deprecated) MySQL is installed and the new (improved) MySQL is installed. This server is using libmysqlclient as the driver.

I'm running my hosting with Arvixe, and they had a blog post that basically said "Run PHP 5.4 and this will work". It's clear to me that they think this function should run, but it's giving me a fatal error instead.

Side note - the code runs perfectly on my local machine, and I only get an error with the call to get_result().

EDITED:

Here is how the PHP is set up:

$stmt = $con->prepare("SELECT * FROM User_Details WHERE LCASE(username) = LCASE(?) LIMIT 1");
  $stmt->bind_param("s", $username);
  $stmt->execute();
  $result = $stmt->get_result(); // This line throws the ugly error
like image 776
drew kroft Avatar asked Jun 23 '15 14:06

drew kroft


4 Answers

For anybody wondering what's going on with this, and using Arvixe. Here is the response I received from the staff.

This is some confusion around MySQLND which was caused by an old platform and its something I'll be communicating to my staff.

We used to run a system which allowed us to have individual PHP installs and at that point 5.4 and 5.5 both had MysqlND running. The new PHP system we have in place runs all PHP installs on a consistent config and therefore with our PHP 5.3 install (the base install) not using MySQLND nor does our 5.4 or 5.5 install.

This will be reviewed in future as PHP 5.6 is going to have MySQLND as a default.

Currently the only way we can support MySQLND is via a VPS / dedicated server.

So, if you're on Arvixe and not a VPS, you're out of luck for using a super common and recommended convention for retrieving data from your database. There are workarounds for this using a ton of different methods. They either aren't feasible for my project or I couldn't get them to work, but for smaller queries it seems that using $stmt->bind_result() is one of the more popular methods. http://php.net/manual/en/mysqli-stmt.bind-result.php

For me, I'm taking my business back to GoDaddy. I spent over 10 hours trying to get a solution for this with no resolution offered except "We have a 60 day money back guarantee if you're not satisfied."

Thanks everyone for helping out with this. Frustrating as it's been, I learned a lot in the process and from these boards... As is usually the case.

like image 135
drew kroft Avatar answered Nov 15 '22 00:11

drew kroft


When you ran the code that inspected the PHP environment was that through the webserver? I ask this because it sounds like you haven't configured your webserver to use PHP 5.4 (which allegedly has the version of mysqli you're after).

You might want to refer to this article from Arvixe.

Interestingly, it seems the function that's causing trouble is available since PHP 5.3.

You might also try a simple script to view the environment from the web

<?php
phpinfo();

Hit that from the web and check for a couple things

  • PHP version 5.4
  • mysqlnd

Personally, I'm not sure mysqlnd is required to provide the get_results function (but would need to dig deeper to determine that).

Another test you can do to see if in fact Arvixe's PHP 5.4 environment provides the function of interest is test the CLI environment which you know has mysqlnd

/opt/ntphp/php54/bin/php -r 'echo method_exists("mysqli_stmt", "get_result") . PHP_EOL;'

If that spits out a 1, you almost certainly just need to follow that guide I linked to earlier to get your webserver environment running PHP 5.4.

like image 43
quickshiftin Avatar answered Nov 15 '22 00:11

quickshiftin


Remove the existing php version and install the new version of php 5.5 or later and verify by doing on root terminal $ php -v

like image 31
GULIM SHAH Avatar answered Nov 15 '22 00:11

GULIM SHAH


Remove the existing php version and install the new version of php 5.5 or later and verify by doing on root terminal $ php -v

like image 22
Gulim Shah Avatar answered Nov 14 '22 22:11

Gulim Shah