Posts Tagged ‘pdo’

Installing Postgres PDO driver on cPanel

Friday, October 5th, 2012 | Life, Tech

cPanel offers two options for installing PDO – using EasyApache which can enable PDO and MySQL’s PDO driver or installing everything via PECL. Unfortunately, under PHP 5.3, the PECL installers don’t work, so if you need any other PDO drivers, you’re in a hole.

Luckily, you can install it manually.

Download the PDO driver from the PECL website. Extract the archive and CD into the directory.

wget http://pecl.php.net/get/PDO_PGSQL
tar -xzf PDO-PGSQL-1.0.2.tgz
cd PDO-PSQL-1.0.2/

Once this is done, run the standard commands for building a PHP extension.

phpize
./configure
make
make install

Once this is done, you can add the extension to php.ini.

cd /usr/local/lib/
vim php.ini
extension=pdo_pgsql.so

Finally, restart Apache and the Postgres driver should show up in your phpinfo() output.

PDO database layer

Wednesday, January 18th, 2012 | Tech

If you’re not using PDO in your PHP projects yet, you should be.

I finally got round to taking a proper look at it recently, and I’m really impressed. I managed to convert an entire open source project to it in under two hours! Granted, I was helped a lot by the fact that the PDO naming conventions luckily match up with the naming conventions I used in my original data access layer, but still, it was smoother than I expected.

PDO has some great advantages too:

1. It’s cross platform, so you can use it on a number of different database platforms including MySQL, MSSQL, Oracle, Postgres, SQLite and many others! All you do is enter the protocol and login details to the connection and it handles everything else.

2. It has prepared queries so you never need to escape anything again! You simple pass it some SQL with a series of question marks in, and an array of values those question marks represent and all the SQL injection negation is taken care for you.

3. If something goes wrong, it throws an exception rather than producing an error message.

4. It’s easy to extend, to add your own functionality. Just use Class MyPDO extends PDO and you can add extra functionality on top of it.

All in all, it’s a great addition to PHP and one I now wish I had gotten to sooner.