我撰写了一个简单的测试脚本来理解MySQLi准备语句。这个脚本将成为一个稍微动态地处理结果的函数的基础。我需要fetch方法返回类似于mysql_fetch_array()的数组。
我知道其中一些方法需要mysqlnd。我已经检查了phpinfo。Mysqlnd已安装并存在。请参见截图。
请注意,PDO可用于我的服务器,但我现在需要让此脚本与MySQLi配合使用。PDO将在项目后期研究。
上述代码的结果为:
致命错误: 在 /path/to/public_html/_test.php 的第 25 行,调用未定义的方法 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'
我知道其中一些方法需要mysqlnd。我已经检查了phpinfo。Mysqlnd已安装并存在。请参见截图。
![enter image description here](https://istack.dev59.com/OQYt5.webp)
![enter image description here](https://istack.dev59.com/j9vx6.webp)
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.php 的第 25 行,调用未定义的方法 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
mysqli_stmt::get_result
仅在PHP 5.3或更高版本中可用。 - Gerald Schneiderprepare
前先尝试使用init
:$stmt = $mysqli->stmt_init(); $stmt->prepare($sql); - jsxqf