How to Know If MySQLnd Is the Active Driver

How to know if MySQLnd is the active driver?

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!';
}

MySQLnd gone missing? How can I work with host provider?

The correct configure option would be --with-mysqli for mysqlnd in mysqli and --with-pdo-mysql for mysqlnd with PDO. Your PHP version has been compiled without mysqlnd or mysqlnd is not enabled (some hosting providers have an option to chose which extension you use e.g. cPanel). However, this would not show in phpinfo() usually.

If your hosting provider changed the PHP version on you without you even knowing, it paints a bad picture of them. I would encourage you to change the hosting provider. It's unforgivable to offer PDO or mysqli without mysqlnd.

The PHP version you use should remain the same until you decide to upgrade. This is important because some versions contain breaking changes. Your PHP executable can't be silently upgraded without your knowledge as it might lead to your application breaking suddenly.

get_result() Doesn't Work even mysqlnd is enabled

To make this thing work, Enable nd_mysqli in php extensions and disable mysqli. This will work like charm!

Query method doesn't work - missing mysqlnd driver

A quite similar approach using call_user_func_array()
You can find some solutions in the Comments section on the manual page

I have no idea why mysqli require all this unnecessary toilsome stuff while PDO does it out of the box. Compare your soon-will-be code with this one:

function query($query, $params=NULL) {
$stmt = $this->pdo->prepare($query);
$stmt->execute($params);
return $stmt->fetchAll();
}


Related Topics



Leave a reply



Submit