They seem to be the same thing, and yet different. I don't know which one is which: I know we can use PDO as new PDO()
and use prepare()
and query()
methods, to fetch data from database. So, if this is PDO
mentioned in the extensions list, then what exactly (in laymans terms) are pdo_mysql and mysqlnd?

- 41,125
- 10
- 61
- 80

- 811
- 2
- 8
- 14
-
See also: http://php.net/manual/en/mysqlinfo.api.choosing.php and http://php.net/manual/en/mysqlinfo.library.choosing.php – mario Jan 23 '17 at 18:03
-
I have read it actually, I just can't still make the connection (no pun intended) between the three of them – ʎɹnɔɹǝW Jan 23 '17 at 18:04
-
1I *think* (and I'm sure someone will correct me if I'm wrong) that mysqlnd is the actual driver that connects PHP to mysql. PDO and mysqli are the APIs that send data through mysqlnd to the mysql server. – aynber Jan 23 '17 at 18:05
-
using PDO in PHP requires the PDO driver, which is what `pdo_mysql` is. Since we want to connect to a mysql db using PDO, we also need the mysql driver, which is what `mysqlnd` is. – random_user_name Jan 23 '17 at 18:05
-
2It sounds like you might not be aware that PDO can be used with many different databases, and not just MySQL. You have to enable the specific extensions for each the type of database you want to use with PDO, (e.g. pdo_mysql for MySQL). – Don't Panic Jan 23 '17 at 18:06
-
the bigger difference is that only PDO supports a dozen different databases http://php.net/manual/en/pdo.drivers.php where `mysql_` and `mysqli_` only support MySQL. – Funk Forty Niner Jan 23 '17 at 18:09
-
Regarding mysqlnd, [this document from the PHP manual](http://php.net/manual/en/mysqlnd.overview.php) will probably help you understand what it is about. An important fact you'll find there is that "it does not provide a new API to the PHP programmer". – Don't Panic Jan 23 '17 at 18:15
-
Let's assume that mysql (software provided by mysql) is actually running and doesn't depend on PHP, because it's a seperate entity, now I am assuming something connects these two applications, but which one of the three is that? and what about the rest? – ʎɹnɔɹǝW Jan 23 '17 at 18:21
-
PDO and PDO_MySQL are the same thing. mysqlnd sits in between PHP and the mysql server, like a post office, or a truck stop waitress (for some reason, my attempt to create a dialogue made mysqlnd sound like a New Yorker...) – aynber Jan 23 '17 at 18:25
-
@aynber How are PDO and PDO_MySQL the same thing? There must be a difference, or are they the identical applications with different name? – ʎɹnɔɹǝW Jan 24 '17 at 07:58
-
The PDO API is installed by the PDO_mysql package, I think. From the docs, `PDO_MYSQL is a driver that implements the PHP Data Objects (PDO) interface to enable access from PHP to MySQL 3.x, 4.x and 5.x databases.` – aynber Jan 24 '17 at 13:17
2 Answers
PDO itself is a database abstraction layer offered by PHP. This may not mean quite what you think it does, but PHP clears that up in the PDO documentation:
PDO provides a data-access abstraction layer, which means that, regardless of which database you're using, you use the same functions to issue queries and fetch data. PDO does not provide a database abstraction; it doesn't rewrite SQL or emulate missing features. You should use a full-blown abstraction layer if you need that facility.
Depending on your system, you might need to enable its driver before you can use it. (But probably not.)
You can use PDO with various different databases (MySQL, Oracle, PostgreSQL, etc.) but you will need to enable the specific driver for the type of database you want to use. From the same PDO introduction documentation I linked earlier:
Note that you cannot perform any database functions using the PDO extension by itself; you must use a database-specific PDO driver to access a database server.
pdo_mysql is one of these. These drivers implement the PDO interface, which means that they allow you to use prepare()
, query()
etc. with your specific database.
mysqlnd
handles the communication between PHP and MySQL. It has been the default driver for all MySQL extensions (like pdo_mysql
) since PHP version 5.4, so if you're using a supported version of PHP, you're probably using it. But it works behind the scenes, just handling the communication. You won't use any mysqlnd
functions. From the "What it is not" section of the mysqlnd
documentation:
Although MySQL Native Driver is written as a PHP extension, it is important to note that it does not provide a new API to the PHP programmer. The programmer APIs for MySQL database connectivity are provided by the MySQL extension, mysqli and PDO MYSQL. These extensions can now use the services of MySQL Native Driver to communicate with the MySQL Server. Therefore, you should not think of MySQL Native Driver as an API.

- 41,125
- 10
- 61
- 80
You need PDO_Mysql to use a mysql database with PDO. It is the driver.
Mysqld is the Mysql server, which you access using PDO or mysqli.
Mysqlnd is the library/the driver to communicate with the Mysql server, both PDO and mysqli use it.

- 280
- 2
- 10
-
5If you're going to answer this, do it right. Show the quotes from the official docs. Also, OP asks about `mysqlnd` - NOT `mysqld`. What you've stated so far is marginal at best, and could just be a comment. – random_user_name Jan 23 '17 at 18:05