2.4 Choosing a library

Copyright 1997-2014 the PHP Documentation Group.

The mysqli, PDO_MySQL and mysql PHP extensions are lightweight wrappers on top of a C client library. The extensions can either use the mysqlnd library or the libmysqlclient library. Choosing a library is a compile time decision.

The mysqlnd library is part of the PHP distribution since 5.3.0. It offers features like lazy connections and query caching, features that are not available with libmysqlclient, so using the built-in mysqlnd library is highly recommended. See the mysqlnd documentation for additional details, and a listing of features and functionality that it offers.

Example 2.2 Configure commands for using mysqlnd or libmysqlclient


// Recommended, compiles with mysqlnd
$ ./configure --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mysql=mysqlnd

// Not recommended, compiles with libmysqlclient
$ ./configure --with-mysqli=/path/to/mysql_config --with-pdo-mysql=/path/to/mysql_config --with-mysql=/path/to/mysql_config

     


Library feature comparison

It is recommended to use the mysqlnd library instead of the MySQL Client Server library (libmysqlclient). Both libraries are supported and constantly being improved.

 MySQL native driver (mysqlnd)MySQL client server library (libmysqlclient)
Part of the PHP distributionYesNo
PHP version introduced5.3.0N/A
LicensePHP License 3.01Dual-License
Development statusActiveActive
LifecycleNo end announcedNo end announced
PHP 5.4 compile default (for all MySQL extensions)YesNo
PHP 5.3 compile default (for all MySQL extensions)NoYes
Compression protocol supportYes (5.3.1+)Yes
SSL supportYes (5.3.3+)Yes
Named pipe supportYes (5.3.4+)Yes
Non-blocking, asynchronous queriesYesNo
Performance statisticsYesNo
LOAD LOCAL INFILE respects the open_basedir directiveYesNo
Uses PHP's native memory management system (e.g., follows PHP memory limits)YesNo
Return numeric column as double (COM_QUERY)YesNo
Return numeric column as string (COM_QUERY)YesYes
Plugin APIYesLimited
Read/Write splitting for MySQL ReplicationYes, with pluginNo
Load BalancingYes, with pluginNo
Fail overYes, with pluginNo
Lazy connectionsYes, with pluginNo
Query cachingYes, with pluginNo
Transparent query manipulations (E.g., auto-EXPLAIN or monitoring)Yes, with pluginNo