MySQLi get_result() undefined when mysqlnd is installed
Asked Answered
P

1

8

I am writing a simple test script to get my head around MySQLi prepared statements. This script will become the basis for a function that needs to be slightly dynamic in its handling of results. I need the fetch method to return as an array similar to how mysql_fetch_array() behaves.

I am aware some of these methods require mysqlnd. I have checked phpinfo. Mysqlnd is installed and present. See screenshot. enter image description here enter image description here

Please note, PDO is available on my server, but I need to get this script working with MySQLi at this time.! PDO will be researched later in this project.

require_once(__ROOT__ . '/config.inc.php');

$mysqli = new mysqli($config['db']['server'], $config['db']['username'], $config['db']['password'], $config['db']['database_name']);
$userid = 10;

$stmt = $mysqli->prepare("SELECT username, firstname, lastname FROM maj_user WHERE user_id < ?");

if ($stmt)
{
    /* bind parameters for markers */
    $stmt->bind_param('i', $userid);

    /* execute query */
    $stmt->execute();
    $result = $stmt->get_result();

    while ($row = $result->fetch_array())
    {
        echo 'We selected "' . $row['username'] . ' (' . $row['firstname'] . ' ' . $row['lastname'] . ')"' . PHP_EOL;
    }

    $result->close();
}

$mysqli->close();

The above code result in:

Fatal error: Call to undefined method mysqli_stmt::get_result() in /path/to/public_html/_test.php on line 25

Php.net says Mysqlnd needs to be present, but that clearly isn't the whole story. What else am I missing?

My PHP configs:

./configure' '--disable-fileinfo' '--enable-bcmath' '--enable-calendar' '--enable-ftp' '--enable-gd-native-ttf' '--enable-libxml' '--enable-pdo=shared' '--enable-sockets' '--prefix=/usr/local' '--with-apxs2=/usr/local/apache/bin/apxs' '--with-curl=/opt/curlssl/' '--with-freetype-dir=/usr' '--with-gd' '--with-imap=/opt/php_with_imap_client/' '--with-imap-ssl=/usr' '--with-jpeg-dir=/usr' '--with-kerberos' '--with-libdir=lib64' '--with-libxml-dir=/opt/xml2/' '--with-mcrypt=/opt/libmcrypt/' '--with-mysql=/usr' '--with-mysql-sock=/var/lib/mysql/mysql.sock' '--with-mysqli=/usr/bin/mysql_config' '--with-openssl=/usr' '--with-openssl-dir=/usr' '--with-pcre-regex=/opt/pcre' '--with-pdo-mysql=shared' '--with-pdo-sqlite=shared' '--with-pic' '--with-png-dir=/usr' '--with-xpm-dir=/usr' '--with-zlib' '--with-zlib-dir=/usr'

Installed PHP and MySQL packages:
cpanel-php54-Horde-Date-2.0.6-1.cp1142
cpanel-php54-Horde-Cache-2.2.1-1.cp1142
cpanel-php54-Horde-Kolab-Session-2.0.1-1.cp1142
cpanel-php54-Horde-Controller-2.0.1-1.cp1142
cpanel-php54-Date-Holidays-0.21.8-1.cp1142
cpanel-php54-SOAP-0.13.0-1.cp1142
cpanel-php54-Date-Holidays-Italy-0.1.1-1.cp1142
cpanel-php54-Net-Sieve-1.3.2-1.cp1142
cpanel-php54-Auth-SASL-1.0.6-1.cp1142
cpanel-php54-Horde-Mime-2.2.5-1.cp1142
cpanel-php54-horde-5.1.4-1.cp1142
cpanel-php54-Horde-Vfs-2.1.1-1.cp1142
cpanel-php54-Horde-Template-2.0.1-1.cp1142
cpanel-php54-horde-lz4-1.0.2-1.cp1142
cpanel-php54-Mail-1.2.0-1.cp1142
cpanel-php54-Date-Holidays-USA-0.1.1-1.cp1142
cpanel-php54-Date-Holidays-Japan-0.1.2-1.cp1142
cpanel-php54-PEAR-Command-Packaging-0.3.0-1.cp1142
cpanel-php54-Console-Table-1.1.5-1.cp1142
cpanel-php54-Horde-Data-2.0.4-1.cp1142
cpanel-php54-nag-4.1.2-1.cp1142
cpanel-php54-Horde-Auth-2.1.0-1.cp1142
cpanel-php54-Horde-Compress-2.0.4-1.cp1142
cpanel-php54-Horde-Text-Diff-2.0.2-1.cp1142
cpanel-php54-Horde-Http-2.0.4-1.cp1142
cpanel-php54-Horde-Secret-2.0.2-1.cp1142
cpanel-php54-Date-Holidays-Brazil-0.1.2-1.cp1142
cpanel-php54-Date-Holidays-Iceland-0.1.2-1.cp1142
cpanel-php54-Horde-Smtp-1.2.3-1.cp1142
cpanel-php54-Net-FTP-1.3.7-3.cp1142
cpanel-php54-Horde-Text-Filter-2.1.3-1.cp1142
cpanel-php54-Horde-Alarm-2.0.4-1.cp1142
cpanel-php54-Horde-SpellChecker-2.1.0-1.cp1142
cpanel-php54-Horde-Share-2.0.4-1.cp1142
cpanel-php54-Horde-Rdo-2.0.2-1.cp1142
cpanel-php54-Date-Holidays-Sweden-0.1.3-1.cp1142
cpanel-php54-Date-Holidays-Portugal-0.1.0-1.cp1142
cpanel-php54-Net-DNS2-1.3.1-1.cp1142
cpanel-php54-content-2.0.3-1.cp1142
cpanel-php54-Horde-Serialize-2.0.2-1.cp1142
cpanel-php54-Horde-Notification-2.0.1-1.cp1142
cpanel-php54-Horde-Text-Flowed-2.0.1-1.cp1142
cpanel-php54-Horde-Routes-2.0.2-1.cp1142
cpanel-php54-Horde-Queue-1.1.1-1.cp1142
cpanel-php54-Horde-Perms-2.1.1-1.cp1142
cpanel-php54-Horde-Feed-2.0.1-1.cp1142
cpanel-php54-Horde-Cli-2.0.4-1.cp1142
cpanel-php54-Mail-Mime-1.8.3-1.cp1142
cpanel-php54-kronolith-4.1.3-3.cp1142
cpanel-php54-Date-Holidays-SanMarino-0.1.1-1.cp1142
cpanel-php54-Date-Holidays-Germany-0.1.2-1.cp1142
cpanel-php54-Date-Holidays-Russia-0.1.0-1.cp1142
cpanel-php54-Date-Holidays-EnglandWales-0.1.5-1.cp1142
cpanel-php54-Cache-1.5.6-1.cp1142 cpanel-php54-XML-SVG-1.1.0-1.cp1142
cpanel-php54-Net-UserAgent-Detect-2.5.2-1.cp1142
cpanel-php54-Horde-Prefs-2.5.0-1.cp1142
cpanel-php54-Horde-Form-2.0.5-1.cp1142
cpanel-php54-webmail-5.1.1-1.cp1142
cpanel-php54-Horde-Translation-2.0.1-1.cp1142
cpanel-php54-Horde-Nls-2.0.3-1.cp1142
cpanel-php54-Horde-Stream-Filter-2.0.2-1.cp1142
cpanel-php54-Horde-Compress-Fast-1.0.2-1.cp1142
cpanel-php54-Net-IMAP-1.1.2-1.cp1142
cpanel-php54-Horde-Pdf-2.0.3-1.cp1142
cpanel-php54-Horde-Stream-Wrapper-2.0.1-1.cp1142
cpanel-php54-Horde-Image-2.0.5-1.cp1142
cpanel-php54-Horde-Service-Facebook-2.0.5-1.cp1142
cpanel-php54-XML-Serializer-0.20.2-1.cp1142
cpanel-php54-Date-Holidays-Norway-0.1.2-1.cp1142
cpanel-php54-Date-Holidays-Croatia-0.1.1-1.cp1142
cpanel-php54-Date-Holidays-PHPdotNet-0.1.2-1.cp1142
cpanel-php54-zendopt-6.0.0-1.cp1142
cpanel-php54-File-Find-1.3.2-1.cp1142
cpanel-php54-Horde-Itip-2.0.5-1.cp1142
cpanel-php54-Horde-Rpc-2.1.0-1.cp1142
cpanel-php54-timeobjects-2.0.4-1.cp1142
cpanel-php54-Horde-Util-2.3.0-1.cp1142
cpanel-php54-Horde-Browser-2.0.4-1.cp1142
cpanel-php54-Horde-LoginTasks-2.0.2-1.cp1142
cpanel-php54-Horde-Tree-2.0.2-1.cp1142
cpanel-php54-Net-SMTP-1.6.2-1.cp1142
cpanel-php54-Horde-Kolab-Format-2.0.4-1.cp1142
cpanel-php54-Horde-Log-2.0.1-1.cp1142
cpanel-php54-Horde-History-2.2.0-1.cp1142
cpanel-php54-5.4.23-4.cp1142
cpanel-php54-Horde-Service-Twitter-2.1.1-1.cp1142
cpanel-php54-XML-Parser-1.3.4-1.cp1142
cpanel-php54-Date-Holidays-Denmark-0.1.3-1.cp1142
cpanel-php54-Date-Holidays-Australia-0.2.1-1.cp1142
cpanel-php54-Date-Holidays-Ukraine-0.1.2-1.cp1142
cpanel-php54-Date-Holidays-Romania-0.1.2-1.cp1142
cpanel-php54-File-1.4.1-1.cp1142 cpanel-php54-ioncube-4.5.2-1.cp1142
cpanel-php54-Console-Color-1.0.3-1.cp1142
cpanel-php54-Horde-Mime-Viewer-2.0.5-1.cp1142
cpanel-php54-Horde-Dav-1.0.2-1.cp1142
cpanel-php54-ingo-3.1.2-3.cp1142 cpanel-php54-MDB2-2.4.1-2.cp1142
cpanel-php54-Horde-Url-2.2.1-1.cp1142
cpanel-php54-Horde-Autoloader-2.0.1-1.cp1142
cpanel-php54-Horde-Xml-Element-2.0.1-1.cp1142
cpanel-php54-Horde-HashTable-1.1.0-1.cp1142
cpanel-php54-Horde-Imsp-2.0.5-1.cp1142
cpanel-php54-Horde-View-2.0.3-1.cp1142
cpanel-php54-Horde-Lock-2.1.0-1.cp1142
cpanel-php54-Horde-Crypt-Blowfish-1.0.2-1.cp1142
cpanel-php54-Net-URL-1.0.15-1.cp1142
cpanel-php54-Services-Weather-1.4.7-1.cp1142
cpanel-php54-Date-Holidays-UNO-0.1.3-1.cp1142
cpanel-php54-Date-Holidays-Austria-0.1.5-1.cp1142
cpanel-php54-Date-Holidays-Venezuela-0.1.1-1.cp1142
cpanel-php54-sourceguardian-8.3-1.cp1142
cpanel-php54-XML-RPC-1.5.5-1.cp1142 cpanel-php54-DB-1.7.14-1.cp1142
cpanel-php54-Horde-Mail-2.1.1-1.cp1142
cpanel-php54-Horde-Timezone-1.0.3-1.cp1142
cpanel-php54-mnemo-4.1.1-1.cp1142
cpanel-php54-Horde-Crypt-2.2.2-1.cp1142
cpanel-php54-HTML-Template-IT-1.3.0-2.cp1142
cpanel-php54-imp-6.1.4-4.cp1142
cpanel-php54-Horde-Exception-2.0.4-1.cp1142
cpanel-php54-Net-Socket-1.0.14-1.cp1142
cpanel-php54-Horde-Editor-2.0.3-1.cp1142
cpanel-php54-Horde-Support-2.1.1-1.cp1142
cpanel-php54-Horde-ElasticSearch-1.0.2-1.cp1142
cpanel-php54-Date-Holidays-Finland-0.1.2-1.cp1142
cpanel-php54-Date-Holidays-Ireland-0.1.3-1.cp1142
cpanel-php54-Log-1.12.7-1.cp1142
cpanel-php54-Horde-SyncMl-2.0.3-1.cp1142
cpanel-php54-Horde-ListHeaders-1.0.1-1.cp1142
cpanel-php54-Horde-Group-2.0.2-1.cp1142
cpanel-php54-Horde-Stream-1.3.0-1.cp1142
cpanel-php54-Horde-Argv-2.0.7-1.cp1142
cpanel-php54-Horde-Db-2.0.4-1.cp1142
cpanel-php54-Horde-SessionHandler-2.2.3-1.cp1142
cpanel-php54-Date-Holidays-Slovenia-0.1.2-1.cp1142
cpanel-php54-Date-Holidays-Turkey-0.1.1-1.cp1142
cpanel-php54-Horde-Core-2.8.0-1.cp1142
cpanel-php54-Horde-Yaml-2.0.2-1.cp1142
cpanel-php54-Date-1.4.7-2.cp1142
cpanel-php54-Horde-Token-2.0.4-1.cp1142
cpanel-php54-Horde-Css-Parser-1.0.1-1.cp1142
cpanel-php54-Horde-Xml-Wbxml-2.0.1-1.cp1142
cpanel-php54-Horde-Date-Parser-2.0.2-1.cp1142
cpanel-php54-Date-Holidays-Serbia-0.1.0-1.cp1142
cpanel-php54-Date-Holidays-Czech-0.1.0-1.cp1142
cpanel-php54-File-Fstab-2.0.3-1.cp1142
cpanel-php54-Text-Figlet-1.0.2-1.cp1142
cpanel-php54-Horde-Icalendar-2.0.7-1.cp1142
cpanel-php54-trean-1.0.3-1.cp1142
cpanel-php54-HTTP-Request-1.4.4-2.cp1142
cpanel-php54-Horde-Role-1.0.1-4.cp1142
cpanel-php54-Horde-Injector-2.0.2-1.cp1142
cpanel-php54-Horde-Constraint-2.0.1-1.cp1142
cpanel-php54-Horde-Oauth-2.0.1-1.cp1142
cpanel-php54-Date-Holidays-Netherlands-0.1.3-1.cp1142
cpanel-php54-Date-Holidays-Spain-0.1.3-1.cp1142
cpanel-php54-HTTP-WebDAV-Server-1.0.0RC8-1.cp1142
cpanel-php54-Horde-Imap-Client-2.15.3-1.cp1142
cpanel-php54-turba-4.1.2-1.cp1142 cpanel-php54-HTTP-1.4.1-2.cp1142
cpanel-mysql-5.1.73-1.cp1136 cpanel-mysql-libs-5.1.73-1.cp1136
cpanel-perl-514-DBD-mysql-4.027-2.cp1146
Petigny answered 23/12, 2014 at 17:20 Comment(24)
and your question is?Bushweller
The question is: Why are some of my MySQLi methods undefined when mysqlnd is installed?Petigny
stackoverflow.com/a/8343970 after Goo-gah-ling "Call to undefined method mysqli_stmt::get_result()"Vegetarianism
What's your PHP version? mysqli_stmt::get_resultis only available in PHP 5.3 or newer.Baro
And please show the portion of the phpinfo() output which relates to mysqli itself (which probably comes right before the mysqlnd section). It should show whether the client library is mysqlnd or mysql (for some reason) I'm not sure it's even possible for both to be loaded though. The <5.3 issue is more likely.Disappointment
My PHP version is 5.4.33.Petigny
@GeraldSchneider I have added that screenshot for you.Petigny
@Fred-ii- Your link was not useful. Most of the answers there cite mysqlnd not being installed. In my case, it is. The reply to bekay by the original poster led me on a goose chase. There is no instance of "extension=php_mysqli_mysqlnd.dll" in my php.ini file. My server admin thinks it may be an Apache config instead and he is looking into it, but this post was not really helpful. It would be nice if I could tell my server admin exactly what I need done.Petigny
If you've done any modifications to any .ini files, and haven't restarted anything including Apache, then that could be an additional factor. What type of webserver are you using?Vegetarianism
have you tried to issue the command > php -m or php -i to see the list of loaded modules and what are your configs? and if "extension=php_mysqli_mysqlnd.dll" is not in your php.ini file, have you tried adding it to php.ini file, (being that .dll in present in the extensions dir) and restarted apache?Aquileia
@Aquileia We have not made any changes to the server yet until we have a better idea of what we need done. I went digging through the extensions directory and found only .so files in there. No components of MySQLi among them. I added my configs to the original post for you.Petigny
@Petigny please reboot the serverScherzo
you're issue could be resolved if you renamed extension= php_mysqli_mysqlnd.dll to php_mysqli.dll, restart apache, give it a tryAquileia
I did a search through the server and this file could not be found.Petigny
@Petigny check this link someone Anonymous posted a workaround at the last post, would this help you ?Scherzo
I've seen this before. I am very reluctant to rely on eval solutions and will only do so if I exhaust all possibilities of getting the proper functionality.Petigny
What kind of server is this? Ubuntu? CentOS? Did you compile this yourself or install packages? Can you list the packages if so?Mora
@Mora The server is a CentOS 5.11. I did not compile it myself. I have SSH access. I just need to contact my server admin to change anything. How do I get the packages?Petigny
rpm -qa php* will list all your PHP packages. You should have one called php-mysqlnd. What repo are you using?Mora
@Mora The command you provided produced no results. I altered the command to "rpm -qa php" and produced the results I added to the original post above. I also included the MySQL packages at the bottom.Petigny
If you get really stuck and cannot get the '$result->fetch_array()' to work then the user supplied examples in the manual provide functions that provide the same functionality mysqli-stmt.get-resultIndiscriminate
I addressed that already just a few replies up, Ryan.Petigny
try init before prepare: $stmt = $mysqli->stmt_init(); $stmt->prepare($sql);Dumm
@jsxqf it's just not going to work without the mysqli API extension installed for mysqlnd (see my answer). The OP's code is taken straight from the example in the PHP manual--there is nothing wrong with it.Primrosa
P
5

I believe the answer lies in your mysqlnd output.

You only have the extension for PDO installed (pdo_mysql), but there is another extension for mysqli (ext/mysqli)

Here are instructions on installing with mysqli API extension

./configure --with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
[other options]

And some more information on the extensions.

Primrosa answered 31/12, 2014 at 7:29 Comment(2)
We had to open a ticket with the server hosts asking them to investigate the problem. As of this morning, all is working. After looking at the configs, they appear to have done precisely what you suggested. In phpinfo, the API Extensions under mysqlnd now show "mysqli,pdo_mysql," which may have resulted from this reconfiguration.Petigny
Awesome! Glad to hear the issue has been resolved. :)Primrosa

© 2022 - 2024 — McMap. All rights reserved.