Installing PDO

Out of the box, Zend Framework's database support works, but it requires an additional piece to function properly when using it with PHP's PDO.

What's PDO, how do you get it, and how can you install it? PDO, which stands for PHP Data Object, is an extension that requires and is included with all PHP 5 installations. PDO allows a PHP developer using different relational database management systems (RDBMSs) to access data in a universal way. If the system used MySQL without the PDO extension, you would execute a query by calling the PHP function mysql_query(). On the other hand, if you used an Oracle database you would need to call the equivalent query execution function oracle_execute(). Using PDO, the call you make to query a table in MySQL is the same for Oracle and Postgres. But don't get it confused with a data abstraction layer; it does not write SQL in any way. You'll leave that piece of the puzzle up to Zend Framework, as you'll see later in the chapter.

There are two ways to install the PDO extension. You can use PECL or you can pull up your sleeves and get dirty editing the php.ini file, which you'll do. Because you want to become an expert at this, take the php.ini path. For starters, you need to make sure that the .dll files that you need were installed during the initial installation process. Open the directory PHP_HOME/ext and see if the following files are present:

• php_pdo.dll for Windows and for Unix-based systems

• php_pdo_mysql.dll (if you're not using MySQL, check for your appropriate .dll file)

If you do not see the files, don't panic. Open the PHP installation zip file, or download it again from the PHP site, and extract the files from the ext drectory to PHP_HOME/ext on the computer. After all the files are extracted to the location, you're one step closer to installing PDO.

Open the php.ini file and search for the following lines:

• extension=php_pdo.dll for Windows and for Unix

• extension=php_pdo_mysql.dll

Uncomment the lines (if you are not using MySQL, uncomment the proper extension) by removing the ; from the front of the line. Save your changes and restart Apache. Congratulations, you now have PDO!

Was this article helpful?

0 0

Post a comment