What is PDO?

  • a PHP5 extension written in a compiled language (C/C++)
  • a Lightweight DBMS connection abstract library (data access abstraction library)

Why PDO?

  • Support great number of database systems supported by PHP
  • You don’t need rewriting of many line code for each database. Just write one and run anywhere
  • Speed. PDO written in compiled language, PHP libraries (ADOdb, PEAR DB) written in an interpreted language
  • Your software more easy to install. Do not need third party software

Whenever you need PDO?

  • You need portable application that support many database system
  • You need speed

How to use PDO?

PDO: Introduction PHP Data Object
 PDO is a PHP5 extension that defines a lightweight DBMs connection abstraction library. Mmm, we ever talk about DMB connection abstraction library (sometimes called data access abstraction library).
What is data access abstraction library? As we know, PHP support several major database, such as mySQL, SQLite, msSQL, and so on. Each connection to those database have unique code. For example, we want to connect to mysql, we wil write:
mysql_connect($host, $user, $password);
If we want to connect to SQLite:
sqlite_open($db, 066);
for postgreSQL:
pg_connect(“host=$host dbname=$db user=$user password=$password”);
What that mean? For example, we have built application base on mysql. When our customer need move to SQLite, we must rebuild our application. We must rewrite many line code. How if our code consist 1,000,000 lines? Nightmare!
Data access abstraction layer will bridge the different. We just write once, and run in every where (like java he he he….)
Next, we talk how to activate PDO extension.

PDO: ACTIVATION PHP DATA OBJECTS EXTENSION

Now, we try to activate this extension.
Open your php.ini. Usually within c:\wamp\bin\php\php5.3.5 (depend on your php installation). Uncomment at line extension=php_pdo.dll, extension=php_pdo_mysql.dll (if you want work with MySQL db), extension=php_pdo_oci.dll (if you want work with oracle db) and also you can others pdo extensions for many more databases.
Restart your apache. You can restart from services. If, you use windows XP, you can access from start > control panel > Performance and Maintenance > Administrative Tools > Services. Find apache, then click restart.


0 comments:

Post a Comment

 
Top
Blogger Template