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 with MySQLnd. Other clients inside PHP, such as the older mysql or the MySQL PDO driver may still be using mysqld.
A better way to check for mysqli with mysqlnd vs mysql with libmysqlclient is to do this:
<?php
$hasMySQL = false;
$hasMySQLi = false;
$withMySQLnd = false;
if (function_exists('mysql_connect')) {
$hasMySQL = true;
$sentence.= "(Deprecated) MySQL <b>is installed</b> ";
} else
$sentence.= "(Deprecated) MySQL <b>is not</b> installed ";
if (function_exists('mysqli_connect')) {
$hasMySQLi = true;
$sentence.= "and the new (improved) MySQL <b>is installed</b>. ";
} else
$sentence.= "and the new (improved) MySQL <b>is not installed</b>. ";
if (function_exists('mysqli_fetch_all')) {
$withMySQLnd = true;
$sentence.= "This server is using MySQLnd as the driver.";
} else
$sentence.= "This server is using libmysqlclient as the driver.";
echo $sentence;
This works because mysqlnd provides three additional functions that work only when mysqlnd is used as the driver. mysqli_fetch_all
is one of these functions, however, it is best to not only check for a function that only shows if mysqli has been compilied with mysqlnd, but also a function that shows if mysqli is compiled at all.
This will allow you to present better error messages to the client.
Finally, the PDO check needs to have the $pdo
variable defined first.
$db = new PDO('mysql:host=localhost;dbname=<SOMEDB>', '<USERNAME>', 'PASSWORD');
if (strpos($pdo->getAttribute(PDO::ATTR_CLIENT_VERSION), 'mysqlnd') !== false) {
echo 'PDO MySQLnd enabled!';
}