Share on Google+Share on Google+


In this tutorial we will study about PDO PgSQL in PHP, how to access PgSQL using PDO, etc. Examples will make this clearer.

PHP-PDO Connectivity with PostgreSQL:

We can connect with PgSQL database using conventional way pg_connect. But in this tutorial we will connect with PDO. Since it is based on object oriented method, we need to instantiate an object of the class PDO. The database connection is handled internally by PDO's constructor (__construct()).



try {

$db = new PDO("pgsql:dbname=db;host=localhost", "postgres", "1234" );

echo "PDO connection object created";


catch(PDOException $e)


echo $e->getMessage();




PDO connection object created




Posted on: April 2, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.


Advertisement null