tags:

views:

1277

answers:

2

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...

+2  A: 

Hi,

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.

Pascal MARTIN
Sorry, I didn't understood your last sentence. "MySQL driver installed -- and that one is compiled based on mysqlnd." It means it's using mysqlnd or not?BTW I'm ussing debian, I don't want to compile and lose the possibility to use apt-get
The Disintegrator
PDO is using "drivers" : one for SQLite, one for Postgre, one for mssql, one for MySQL, ... And, for MySQL, that driver can be compiled to use either libmysql or mysqlnd ;; in your case, it says "mysqlnd"
Pascal MARTIN
+5  A: 

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!';
}
Inspire
Thanks. Finally some Peace of Mind
The Disintegrator