如何知道 MySQLnd 是否是活动驱动程序?

发布于 2024-08-05 23:30:47 字数 840 浏览 5 评论 0原文

也许这是一个显而易见的问题,但我想确定一下。

我如何知道 MySQLnd 是否是活动驱动程序?

我正在运行 PHP 5.3 和 MySQL 5.1.37。 在 phpinfo() 中列出了 mysqlnd,但仅此而已,我无法确定我是否使用 MySQLnd 还是旧驱动程序...

phpinfo() 输出摘录

mysql
MySQL Support   enabled
Active Persistent Links     0
Active Links    0
Client API version  mysqlnd 5.0.5-dev - 081106 - $Revision: 1.3.2.27 $ 

mysqli
MysqlI Support  enabled
Client API library version  mysqlnd 5.0.5-dev - 081106 - $Revision: 1.3.2.27 $
Active Persistent Links     0
Inactive Persistent Links   0
Active Links    26 

mysqlnd
mysqlnd enabled
Version     mysqlnd 5.0.5-dev - 081106 - $Revision: 1.3.2.27 $ 

PDO
PDO support enabled
PDO drivers     mysql

pdo_mysql
PDO Driver for MySQL    enabled
Client API version  mysqlnd 5.0.5-dev - 081106 - $Revision: 1.3.2.27 $ 

我正在使用 PDO,PDO 驱动程序说 mysql...

Maybe it's an obvious question, but I want to be sure.

How can i know if it MySQLnd is the active driver?

I'm runing PHP 5.3 and MySQL 5.1.37.
In phpinfo() mysqlnd is listed but only with this I can't be sure if I'm using MySQLnd or the old driver...

Extract of phpinfo() output

mysql
MySQL Support   enabled
Active Persistent Links     0
Active Links    0
Client API version  mysqlnd 5.0.5-dev - 081106 - $Revision: 1.3.2.27 $ 

mysqli
MysqlI Support  enabled
Client API library version  mysqlnd 5.0.5-dev - 081106 - $Revision: 1.3.2.27 $
Active Persistent Links     0
Inactive Persistent Links   0
Active Links    26 

mysqlnd
mysqlnd enabled
Version     mysqlnd 5.0.5-dev - 081106 - $Revision: 1.3.2.27 $ 

PDO
PDO support enabled
PDO drivers     mysql

pdo_mysql
PDO Driver for MySQL    enabled
Client API version  mysqlnd 5.0.5-dev - 081106 - $Revision: 1.3.2.27 $ 

I'm using PDO, and PDO driver says mysql...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

时间你老了 2024-08-12 23:30:47

警告!此方法不可靠,自 PHP 8.1 起不再起作用

如果您通过 mysqli 访问,这应该可以解决问题:

<?php
$mysqlnd = function_exists('mysqli_fetch_all');

if ($mysqlnd) {
    echo 'mysqlnd enabled!';
}

检测其是否是活动的 PDO 驱动程序,然后创建 MySQL PDO 对象:

if (strpos($pdo->getAttribute(PDO::ATTR_CLIENT_VERSION), 'mysqlnd') !== false) {
    echo 'PDO MySQLnd enabled!';
}

Warning! This method is unreliable and does not work since PHP 8.1

If you are accessing via mysqli, this should do the trick:

<?php
$mysqlnd = function_exists('mysqli_fetch_all');

if ($mysqlnd) {
    echo 'mysqlnd enabled!';
}

To detect if its the active PDO driver, create your MySQL PDO object then:

if (strpos($pdo->getAttribute(PDO::ATTR_CLIENT_VERSION), 'mysqlnd') !== false) {
    echo 'PDO MySQLnd enabled!';
}
如日中天 2024-08-12 23:30:47

检查 mysqli_fetch_all 并不能真正描述您是否正在使用 mysqlnd 。相反,它表示您已启用 mysqli 扩展

MySQLi 只是 PHP 早期版本中提供的 mysql 扩展的更新版本。

mysql 扩展、mysqli 扩展和 PDO MySQL 驱动程序 都可以单独配置为使用
libmysqlclient 或 mysqlnd

此代码:

<?php
$mysqlnd = function_exists('mysqli_fetch_all');

if ($mysqlnd) {
    echo 'mysqlnd enabled!';
}

不回显任何内容表明您没有编译/启用/安装 mysqli,并且可能正在使用旧的 mysql 扩展。

使用 mysqlnd 检查 mysqli 与使用 libmysqlclient 的 mysql 的更好方法是这样做:

<?php
if (function_exists('mysql_connect')) {
    echo "- MySQL <b>is installed</b>.<br>";
} else  {
    echo "- MySQL <b>is not</b> installed.<br>";
}

if (function_exists('mysqli_connect')) {
    echo "- MySQLi <b>is installed</b>.<br>";
} else {
    echo "- MySQLi <b>is not installed</b>.<br>";
}

if (function_exists('mysqli_get_client_stats')) {
    echo "- MySQLnd driver is being used.<br>";
} else {
    echo "- libmysqlclient driver is being used.<br>";
}

这有效,因为 mysqlnd 提供了三个附加函数,仅当 mysqlnd 用作驱动程序时才起作用

最后,PDO 检查需要首先定义 $pdo 变量。

$dbHost = "localhost";
$dbUser = "root";
$dbPass = "password";
$dbName = "database";

$pdo = new PDO('mysql:host='.$dbHost.';dbname='.$dbName, $dbUser, $dbPass);
if (strpos($pdo->getAttribute(PDO::ATTR_CLIENT_VERSION), 'mysqlnd') !== false) {
    echo '- PDO MySQLnd <b>is enabled</b>.<br>';
} else {
    echo '- PDO MySQLnd <b>is not enabled</b>.<br>';
}
?>

Checking for mysqli_fetch_all does not really describe wether you are using mysqlnd. Rather, it says that you have the mysqli extension enabled.

MySQLi is simply an updated version of the mysql extension that was provided in earlier versions of PHP.

The mysql extension, the mysqli extension and the PDO MySQL driver can each be individually configured to use either
libmysqlclient or mysqlnd

This code:

<?php
$mysqlnd = function_exists('mysqli_fetch_all');

if ($mysqlnd) {
    echo 'mysqlnd enabled!';
}

not echoing nothing suggests that you don't have mysqli compiled/enabled/installed, and might be using the older mysql extension.

A better way to check for mysqli with mysqlnd vs mysql with libmysqlclient is to do this:

<?php
if (function_exists('mysql_connect')) {
    echo "- MySQL <b>is installed</b>.<br>";
} else  {
    echo "- MySQL <b>is not</b> installed.<br>";
}

if (function_exists('mysqli_connect')) {
    echo "- MySQLi <b>is installed</b>.<br>";
} else {
    echo "- MySQLi <b>is not installed</b>.<br>";
}

if (function_exists('mysqli_get_client_stats')) {
    echo "- MySQLnd driver is being used.<br>";
} else {
    echo "- libmysqlclient driver is being used.<br>";
}

This works because mysqlnd provides three additional functions that work only when mysqlnd is used as the driver.

Finally, the PDO check needs to have the $pdo variable defined first.

$dbHost = "localhost";
$dbUser = "root";
$dbPass = "password";
$dbName = "database";

$pdo = new PDO('mysql:host='.$dbHost.';dbname='.$dbName, $dbUser, $dbPass);
if (strpos($pdo->getAttribute(PDO::ATTR_CLIENT_VERSION), 'mysqlnd') !== false) {
    echo '- PDO MySQLnd <b>is enabled</b>.<br>';
} else {
    echo '- PDO MySQLnd <b>is not enabled</b>.<br>';
}
?>
半仙 2024-08-12 23:30:47

驱动程序(libmysql 或 mysqlnd)是在编译时选择的,并且可以为 mysql、mysqli 和 pdo_mysql 独立指定这两个驱动程序中的每一个。

以下是与 mysqlnd 对应的三个配置选项:

  --with-mysql[=DIR]      Include MySQL support.  DIR is the MySQL base
                          directory.  If mysqlnd is passed as DIR,
                          the MySQL native driver will be used [/usr/local]
  --with-mysqli[=FILE]    Include MySQLi support.  FILE is the path
                          to mysql_config.  If mysqlnd is passed as FILE,
                          the MySQL native driver will be used [mysql_config]
  --with-pdo-mysql[=DIR]    PDO: MySQL support. DIR is the MySQL base directoy
                                 If mysqlnd is passed as DIR, the MySQL native
                                 native driver will be used [/usr/local]

在您的情况下,mysql、mysqli 和 pdo_mysql 的“客户端 API 版本”均为“mysqlnd 5.0.5-dev”。

所以看来你在这三种情况下都使用 mysqlnd 。

对于 PDO,您已经安装了 MySQL 驱动程序——并且该驱动程序是基于 mysqlnd 编译的。

The driver (libmysql or mysqlnd) is choosen at compile-time, and each one of those two can be specified independatly for mysql, mysqli, and pdo_mysql.

Here are the three configure options that correspond to mysqlnd :

  --with-mysql[=DIR]      Include MySQL support.  DIR is the MySQL base
                          directory.  If mysqlnd is passed as DIR,
                          the MySQL native driver will be used [/usr/local]
  --with-mysqli[=FILE]    Include MySQLi support.  FILE is the path
                          to mysql_config.  If mysqlnd is passed as FILE,
                          the MySQL native driver will be used [mysql_config]
  --with-pdo-mysql[=DIR]    PDO: MySQL support. DIR is the MySQL base directoy
                                 If mysqlnd is passed as DIR, the MySQL native
                                 native driver will be used [/usr/local]

In your case, the "Client API version" is "mysqlnd 5.0.5-dev" for both mysql, mysqli, and pdo_mysql.

So it seems you ahre using mysqlnd in either three cases.

In the case of PDO, you have the MySQL driver installed -- and that one is compiled based on mysqlnd.

究竟谁懂我的在乎 2024-08-12 23:30:47

这就是我一直在寻找的

<?php
if (extension_loaded('mysqlnd')) {
}
?>

This is what I was looking for

<?php
if (extension_loaded('mysqlnd')) {
}
?>
我爱人 2024-08-12 23:30:47

也许检查这些设置是否存在?由于某种原因,phpinfo() 呈现它们的方式与其他 ini 设置不同。适用于 5.4,不确定 5.3 是否适用。

ini_get('mysqlnd.debug') !== false

Maybe check if these settings exist? phpinfo() renders them differently from other ini settings for some reason. Works for 5.4, not sure about 5.3.

ini_get('mysqlnd.debug') !== false
深爱成瘾 2024-08-12 23:30:47

phpinfo() 在开头列出了用于编译 PHP 的“配置命令”。

正如他们在其他答案中所述,mysqlnd 是 php 安装/编译过程中 2 个选择中的 1 个(默认值)。

我的 7.0.33 的 phpinfo 配置命令是:

'./configure' '--prefix=/opt/php70' '--with-libdir=lib64' '--enable-bcmath' '--enable-calendar' '- -enable-dbase' '--enable-exif' '--enable-ftp' '--enable-gd-native-ttf' '--enable-intl' '--enable-libxml' '--enable-mbstring ' '--enable-pdo' '--enable-soap' '--enable-sockets' '--enable-sqlite-utf8' '--enable-wddx' '--enable-zip' '--with- bz2' '--with-curl' '--with-freetype-dir' '--with-gd' '--with-gettext' '--with-gmp' '--with-imap' '--with -imap-ssl''--with-jpeg-dir=/usr''--with-kerberos''--with-mcrypt''--with-mhash''--with-mssql''--with- mysql=/usr' '--with-mysql-sock=/var/lib/mysql/mysql.sock' '--with-mysqli=/usr/bin/mysql_config' '--with-openssl' '--with -pdo-mysql=/usr' '--with-pdo-pgsql=/usr' '--with-pgsql=/usr' '--with-pdo-sqlite' '--with-png-dir' '- -with-pspell''--with-sqlite''--with-system-tzdata''--with-tidy''--with-unixODBC''--with-xmlrpc''--with-xsl'' --with-zlib'

注意 --with-mysqli=/usr/bin/mysql_config' '

和 --enable-mysqlnd' ' (不是这个,而是 5.6 php 版本上的读数)

--with-mysqli= 是指向一个目录,意味着它正在使用 libmysqlclient
如果是 mysqlnd,那么它正在使用本机驱动程序。

有关此的更多信息 http://php.net/manual/en/mysqlinfo .library.choosing.php

(我知道这已经很老了,但是这些知识可以帮助我节省几个小时的技术支持辩论时间,而且我是第一次看到这个。)

phpinfo() in the beginning lists the "Configure Command" used to compile PHP.

As they state in other answers mysqlnd is 1 (the default) of 2 choices during the php install/compile process.

My phpinfo Configure Command for 7.0.33 is:

'./configure' '--prefix=/opt/php70' '--with-libdir=lib64' '--enable-bcmath' '--enable-calendar' '--enable-dbase' '--enable-exif' '--enable-ftp' '--enable-gd-native-ttf' '--enable-intl' '--enable-libxml' '--enable-mbstring' '--enable-pdo' '--enable-soap' '--enable-sockets' '--enable-sqlite-utf8' '--enable-wddx' '--enable-zip' '--with-bz2' '--with-curl' '--with-freetype-dir' '--with-gd' '--with-gettext' '--with-gmp' '--with-imap' '--with-imap-ssl' '--with-jpeg-dir=/usr' '--with-kerberos' '--with-mcrypt' '--with-mhash' '--with-mssql' '--with-mysql=/usr' '--with-mysql-sock=/var/lib/mysql/mysql.sock' '--with-mysqli=/usr/bin/mysql_config' '--with-openssl' '--with-pdo-mysql=/usr' '--with-pdo-pgsql=/usr' '--with-pgsql=/usr' '--with-pdo-sqlite' '--with-png-dir' '--with-pspell' '--with-sqlite' '--with-system-tzdata' '--with-tidy' '--with-unixODBC' '--with-xmlrpc' '--with-xsl' '--with-zlib'

Note --with-mysqli=/usr/bin/mysql_config' '

and --enable-mysqlnd' ' (Not in this one but a readout on a 5.6 php build)

--with-mysqli= is pointing to a directory meaning it is using libmysqlclient
If it was mysqlnd instead then it is using the native driver.

For more info on this http://php.net/manual/en/mysqlinfo.library.choosing.php

(I know this is way old however this knowledge would have saved me hours of tech support debate and I seen this first.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文