| CARVIEW |
The world's most popular open source database
MySQL native driver for PHP - mysqlnd
The PHP script language features three different "extensions" to connect to the MySQL Server. The PHP term "extension" is comparable to the MySQL terms "Connector" and "Driver", please check the MySQL Reference Manual for details. The following extensions exist:
- ext/mysql
- ext/mysqli
- PDO_MYSQL
All PHP MySQL extensions are part of the source code of PHP. The source code and binaries are available from https://php.net. Both the PHP manual and the MySQL Reference Manual contain a detailed documentation of which extension to use.
The MySQL native driver for PHP is an additional, alternative way to connect from PHP 5.3 or newer to the MySQL Server 4.1 or newer. It is a replacement for the libmysql, the MySQL Client Library. As of PHP 5.3 you can use ext/mysql, ext/mysqli and PDO_MYSQL either together with libmysql as you did in the past or with mysqlnd.
We have no plans to remove libmysql support from ext/mysql, ext/mysqli or PDO_MYSQL, which would break existing applications. We just add a new, superior alternative to our PHP offerings.
Getting and installing mysqlnd
The MySQL native driver for PHP is part of the official PHP source code repository at https://php.net. It is contained in the PHP source code as of PHP 5.3. You can download the source and windows binaries from https://php.net. The PHP CVS repository contains the latest stable version and is the main development platform. Please see the PHP manual or the MySQL Reference Manual for detailed installation instructions. If you are compiling PHP yourself, please use the configure options --with-mysql=mysqlnd, --with-mysqli=mysqlnd and --with-pdo-mysql=mysqlnd to compile PHP with mysqlnd support.Advantages of mysqlnd
The MySQL native driver for PHP (mysqlnd) is licensed under the terms of the PHP license to solve any license issues.
On the C-level mysqlnd uses many of the proven and stable PHP internal functions. All the code of the new driver is contained in the ext/mysqlnd directory of the PHP source code as of PHP 5.3. There is no need to link any external libraries. Thus you neither need to install the MySQL Client Library to compile PHP with ext/mysql, ext/mysqli and/or PDO_MYSQL support nor do you need to take care of versions. Compiling has been made easier.
The performance of some functions has been improved. We have measured considerable performance improvements, for example when fetching buffered result sets.
Features and Limitations
The current release covers the functionality of the libmysql beside some functions that are marked as experimental in the PHP documentation.
The MySQL native driver for PHP does not support the MySQL Server 4.0 or earlier. The MySQL Server 4.0 is no longer supported by MySQL as of 2008-12-31, see also MySQL Lifecycle Policy.
From the API additions discussed with Community members in November 2006 during the Frankfurt PHP conference, we managed to implement:
- improved persistent connections
- mysqli_fetch_all()
- performance statistics call: mysqli_get_cache_stats(), mysqli_get_client_stats(), mysqli_get_connection_stats()
More additions will follow.
FAQ
Q: Is mysqlnd a new PHP extension?
No, the new MySQL driver for PHP is not a new PHP extension. The driver is a replacement for the MySQL Client Library on the internal C level of the PHP extensions ext/mysql, ext/mysqli and PDO_MYSQL.
You can continue to compile the any of the above mentioned extension with the MySQL Client Library like ever since. We will not remove this functionality. Alternatively you can compile the extensions with mysqlnd. We suggest that you try it, because mysqlnd is easier to compile and we found it to be faster than the MySQL Client Library.
Q: Can other PHP extensions use it?
Yes, they can, if they want to. The source code of the new driver is the ext/mysqlnd directory of the download files. Extension writers will find that mysqlnd mimics the API of MySQL Client Library respectively the MySQL C API.
Q: Does PDO/MySQL support it?
Yes, the MySQL driver for PDO supports mysqlnd.
Q: Does it work with any MySQL Server before 4.1?
The MySQL native driver for PHP requires PHP 5.3 or PHP 6. You can use it to connect to the MySQL Server 4.1 or newer. Please note the MySQL Lifecycle Policy at https://www.mysql.com/about/legal/lifecycle/.
Q: Does it offer all functionality of the MySQL Client Library?
No, compression and SSL support are currently missing.
Q: How can I contribute and/or report bugs?
For development discussion and reporting bugs please subscribe to the mailing list php@lists.mysql.com. See https://lists.mysql.com/ for details.
Please report bugs at https://bugs.php.net.
Q: What is next on your mysqlnd TODO?
With the delivery of mysqlnd support for PDO_MYSQL and the release of PHP 5.3, the development of the first stable release has been completed. During the next months, we will focus on optimization and performance tuning. The experimental branches, available at Launchpad, unveil some of our future ideas. However, we would be happy to learn about your needs and appreciate your feedback.
Experimental features
Additional experimental and unsupported branches can be found at the MySQL Launchpad web site at https://code.launchpad.net/mysql. The experimental branches contain features which might or might not go into the stable tree at any time later. Currently the following PHP related branches exist:
- https://code.launchpad.net/~andrey-mysql/php-mysqlnd/trunk - basically identical to PHP CVS
- https://code.launchpad.net/~andrey-mysql/php-mysqlnd/binary_protocol - binary protocol for COM_QUERY
- https://code.launchpad.net/~johannes-s/php-mysqlnd/mysqli-to-stream - converting a ext/mysqli handle into a PHP Stream for filtering
- https://code.launchpad.net/~johannes-s/php-mysqlnd/pdo2mysqli - converting a ext/mysqli connection into a PDO_MYSQL connection
- https://code.launchpad.net/~mysql/mysqlndstat/trunk - satistics aggregation for PHP's mysqlnd extension


