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?
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.
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.
mysqlnd
- NOT mysqld
. What you've stated so far is marginal at best, and could just be a comment. –
Refute © 2022 - 2024 — McMap. All rights reserved.
pdo_mysql
is. Since we want to connect to a mysql db using PDO, we also need the mysql driver, which is whatmysqlnd
is. – Refutemysql_
andmysqli_
only support MySQL. – GardiaPDO_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.
– Haematoxylin