PDO(PHP Data Objects) is one of main feature of PHP 5.1 to managing databases. It is developed to provide a lightweight interface for different database engines. And one of the very good features of PDO is that it works like a Data Access Layer so that you can use the same function names for all database engines.
PHP Script
<?php $db_name ='test_db'; $db_host = 'localhost'; $db_user = 'root'; $db_password = 'mypassword'; $dsn = 'mysql:dbname=$db_name;host=$db_host;'; $connectionString = new PDO($dsn, $db_user, $db_password); ?>
The DSN settings for different database engines to connect with PDO. Supported database drivers are as shown below:
PDO_DBLIB for FreeTDS/Microsoft SQL Server/Sybase
mssql:host=localhost;dbname=test_db sybase:host=localhost;dbname=test_db dblib:host=localhost;dbname=test_db
PDO_INFORMIX for IBM Informix Dynamic Server
informix:host=host.domain.com;service=9800;database=test_db; server=ids_server;protocol=onsoctcp;
EnableScrollableCursors=1;
PDO_MYSQL for MySQL 3.x/4.x/5.x
mysql:host=localhost;port=3307;dbname=test_db mysql:unix_socket=/tmp/mysql.sock;dbname=test_db
PDO_OCI for Oracle Call Interface
oci:mydb oci:dbname=//localhost:1521/test_db
PDO_ODBC for ODBC v3 (IBM DB2, unixODBC and win32 ODBC)
odbc:test_db
odbc:DRIVER={IBM DB2 ODBC DRIVER};HOSTNAME=localhost;PORT=50000;DATABASE=test_db;
PROTOCOL=TCPIP;UID=db_user_name;PWD=db_password;
odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=C:db.mdb;Uid=Admin
PDO_PGSQL for PostgreSQL
pgsql:dbname=test_db;user=db_user_name;password=db_password; host=localhost;port=5432
PDO_SQLITE for SQLite 3 and SQLite 2
sqlite:/opt/databases/mydb.sq3 sqlite::memory: sqlite2:/opt/databases/mydb.sq2 sqlite2::memory:
PDO_FIREBIRD for Firebird/Interbase 6
firebird:user="db_user_name;Password=db_password; Database=DATABASE.GDE;DataSource=localhost;Port=3050;

Share Your Thoughts