How do I enable php to work with postgresql?

Aaron picture Aaron · May 17, 2012 · Viewed 191.5k times · Source
<?php

try {
   $dbh = new PDO('pgsql:host=localhost;port=5432;dbname=###;user=###;password=##');
   echo "PDO connection object created";
}
catch(PDOException $e)
{
      echo $e->getMessage();
}

?>

I get the error message "Could Not Load Driver"

Answer

Jorge Olivares picture Jorge Olivares · May 17, 2012

You need to install the pgsql module for php. In debian/ubuntu is something like this:

sudo apt-get install php5-pgsql

Or if the package is installed, you need to enable de module in php.ini

extension=php_pgsql.dll (windows)
extension=php_pgsql.so (linux)

Greatings.