Use php’s PDO(PHP Database Object) for database access

by in , on

PDO(PHP Database Object) in php 5.1 is a better way to collecting data from the database in the form of Objects. PDO provides you the freedom to switching any databse just by switching the connection.

Here are some Databases Supported by PDO:

  2. PDO_DBLIB : Microsoft SQL Server and Sybase
  4. PDO_SQLITE : SQLite
  5. PDO_FIREBIRD : Firebird/Interbase
  6. PDO_INFORMIX : Informix
  7. PDO_IBM : IBM
  8. PDO_SQLSRV : Microsoft SQL Server
  9. PDO_OCI : Oracle
  10. PDO_ODBC : ODBC and DB2
  11. PDO_PGSQL : PostgreSQL
  12. PDO_4D : 4D

Or simple you can check in your system to use:


Here are some examples of select, insert, update and delete query. But first of all we should that how to make a connection with PDO.

PDO Connection with MySQL:


Here is the complete connection block. Make sure the Database values before apply this example.


To know more about the PDO(PHP Database Object) follow the link PDO

Select Query:


Insert Query:

In this insert query i am using named placeholders instead of the direct query. Also remember that named placeholder always start with colon. In this example first prepare the query and give the named placeholder then bind it with the assigned variables then execute it.


Update Query:


Delete Query:


The above are the basic examples of PDO(PHP Database Object).