What is PDO?


PDO stands for PHP Data Objects (PHP Extension) is a lightweight, consistence interface used to access database. Example it can be used in place with MySQLi (MySQL improved)

-Lean and consistence way to access the database

-Works with multiple databases

-Data access layer

-Object Oriented.


  1. PDO and MySQLi are equivalent in terms of security
  • Both support prepared statements
  • No risk of SQL injection.
  1. Unlike MySQLi, PDO supports named parameters
  • This makes working with database field easier
  1. Unlike MySQLi, PDO supports many different vendors
  2. Secure, flexible, easy
  3. Best Choice for all new projects and updates.
  4. PDO Object-oriented programming API, WHILE MySQLi both object-oriented and procedural.

Some benefits of PDO

  1. Multiple Databases, it does not support syntax that just specific to a certain database, in some cases you switches the connection string to change the database you are working with i.e. change MySQL to PostgreSQL
  2. Security / Prepared Statements. It is one biggest benefit of PDO, it uses prepare statements which can help to prevent you are database from SQL injections. SQL injections in simple term is if someone tries to insert SQL statements and instruction through some user input like a form in your website that can destroy your database.  Prepared Statement is a pre compiled SQL statement that separate the instruction of the SQL statement from the data
  3. Usability. It has function that can perform routine operations for fetching data and exceptions
  4. Reusability. It has unify API to access multiple databases
  5. Excellent Error handling options i.e. silence, warning and exception.


Main PDO classes

  1. PDO, Represents a connection between PHP and DB (Database), this is where we plug in the DSN.
  2. PDOStatement, Represents a prepared statement and after executed an associated result.
  3. PDOException, Represent errors raised by PDO.


Databases that can be used with PDO

Here are the some databases that can be used with PDO.

  1. MySQL
  2. PostgreSQL
  3. MS SQL Server
  4. Oracle
  5. FireBird
  6. Sybase
  7. IBM
  8. Informix
  9. SQLite
  10. FreeTDS
  11. 4D
  12. Cubrid.

Other Recommended for you

  • .What is Cloud Firestore? Android Studio
  • .Firebase Realtime Database vs Firestore.
  • .What is an Intent in Android? Types of Intent
  • .What is Firebase?