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...
By default it must be checked for your hosting ( depends on the version of PHP you are using ) , you can enable or disable this by visiting CPanel and then PHP Version link.
The MySQL native driver for PHP (mysqlnd) is a drop-in replacement for the MySQL Client Library (libmysql) for the PHP script language.
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!'; }
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, themysqli
extension and thePDO 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>'; } ?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With