- SO: Windows/Linux
- HTTP Web Server: Apache
- Programming language: PHP
Enable PHP to work with PostgreSQL in Apache
In Apache I edit the following configuration file: C:\xampp\php.ini
I make sure to have the following lines uncommented:
extension=php_pgsql.dll
extension=php_pdo_pgsql.dll
Finally restart Apache before attempting a new connection to the database engine.
Also, I leave my code that ensures that the connection is unique:
private static $pdo = null;
public static function provideDataBaseInstance() {
if (self::$pdo == null) {
$dsn = "pgsql:host=" . HOST .
";port=5432;dbname=" . DATABASE .
";user=" . POSTGRESQL_USER .
";password=" . POSTGRESQL_PASSWORD;
try {
self::$pdo = new PDO($dsn);
} catch (PDOException $exception) {
$msg = $exception->getMessage();
echo $msg .
". Do not forget to enable in the web server the database
manager for php and in the database instance authorize the
ip of the server instance if they not in the same
instance.";
}
}
return self::$pdo;
}
GL