安装 mysqlnd 时未定义 MySQLi get_result()

Posted

技术标签:

【中文标题】安装 mysqlnd 时未定义 MySQLi get_result()【英文标题】:MySQLi get_result() undefined when mysqlnd is installed 【发布时间】:2015-02-21 20:59:57 【问题描述】:

我正在编写一个简单的测试脚本来了解 mysqli 准备好的语句。该脚本将成为在处理结果时需要稍微动态的函数的基础。我需要 fetch 方法以类似于 mysql_fetch_array() 行为方式的数组形式返回。

我知道其中一些方法需要 mysqlnd。我检查了phpinfo。 Mysqlnd 已安装并存在。见截图。

请注意,PDO 在我的服务器上可用,但我现在需要让这个脚本与 MySQLi 一起使用。!本项目稍后会研究 PDO。

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();

以上代码结果:

致命错误:在 /path/to/public_html/_test.php25 中调用未定义方法 mysqli_stmt::get_result() >

Php.net 说 Mysqlnd 需要存在,但这显然不是全部。我还缺少什么?

我的 PHP 配置:

./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

【问题讨论】:

你的问题是? 问题是:为什么我安装mysqlnd的时候有些MySQLi方法没有定义? ***.com/a/8343970 在 Goo-gah-ling "调用未定义方法 mysqli_stmt::get_result()" 之后 你的 PHP 版本是多少? mysqli_stmt::get_result仅适用于 PHP 5.3 或更高版本。 请显示与mysqli 本身相关的phpinfo() 输出部分(可能就在mysqlnd 部分之前)。它应该显示客户端库是 mysqlnd 还是 mysql (出于某种原因)我不确定是否有可能同时加载两者。 【参考方案1】:

我相信答案就在你的 mysqlnd 输出中。

您只安装了 PDO 的扩展程序 (pdo_mysql),但还有另一个 mysqli 扩展程序 (ext/mysqli)

这里是instructions on installing with mysqli API extension

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

还有更多information on the extensions.

【讨论】:

我们不得不向服务器主机开一张票,要求他们调查问题。截至今天早上,一切正常。查看配置后,他们似乎完全按照您的建议完成了。在 phpinfo 中,mysqlnd 下的 API Extensions 现在显示“mysqli,pdo_mysql”,这可能是这次重新配置的结果。 太棒了!很高兴听到问题已解决。 :)

以上是关于安装 mysqlnd 时未定义 MySQLi get_result()的主要内容,如果未能解决你的问题,请参考以下文章

mysql-mysqli_fetch_all(错误)

MySQLi以数组形式获取[重复]

PHP编译安装命令

编译安装PHP5.5.32的配置文件

编译安装php7.3

如何在 MacOS 上安装 MySQLi