Using PDO to connect to a database
PDO is a highly performant and actively maintained database extension that has a unique advantage over vendor-specific extensions. It has a common Application Programming Interface (API) that is compatible with almost a dozen different Relational Database Management Systems (RDBMS). Learning how to use this extension will save you hours of time trying to master the command subsets of the equivalent individual vendor-specific database extensions.
PDO is subdivided into four main classes, as summarized in the following table:
Class |
Functionality |
---|---|
|
Maintains the actual connection to the database, and also handles low-level functionality such as transaction support |
|
Processes results |
|
Database-specific exceptions |
|
Communicates with the actual vendor-specific database |
How to do it...
Set up the database connection by creating a
PDO
instance.You need to construct a Data Source Name (DSN). The information contained in...