连接PostgreSQL数据库和php


connect PostgreSQL DB and php

I inastall php 5.4、apache和postgresql 9.2在Windows 7操作系统上。

现在,我正在尝试从php文件连接到postgresqlDB,这是php连接代码:

$dbconn = pg_connect("host=localhost dbname=postgres user=postgres password=pass");

这给出:Call to undefined function pg_connect()

php.ini文件中,我有:extension="path'to'extension'php_pgsql.dll"

导致此错误的原因是什么?

我也尝试过使用pg_connect连接到数据库,但我得到了错误:调用未定义的函数。我已经使用PDO连接到数据库。这似乎奏效了。

<?php
try {
$dbuser = 'postgres';
$dbpass = 'your password';
$host = 'localhost';
$dbname='dbname';
$connec = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
}catch (PDOException $e) {
echo "Error : " . $e->getMessage() . "<br/>";
die();
}
?>