0

I inastall php 5.4, apache and postgresql 9.2 on Windows 7 OS.

Now, I am trying connect to postgresql DB from php file, this is php connect code:

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

This gives: Call to undefined function pg_connect()

In php.ini file I have: extension="path\to\extension\php_pgsql.dll"

What may causes this error?

Chris Travers
  • 25,424
  • 6
  • 65
  • 182
Oto Shavadze
  • 40,603
  • 55
  • 152
  • 236
  • 1
    Anything useful at http://stackoverflow.com/questions/7438059/fatal-error-call-to-undefined-function-pg-connect ? – bma Jul 07 '13 at 20:57
  • I have `extension="path\to\extension\php_pgsql.dll` in php.ini file. This extension exists on specified path. After restarting apache webserver, I see phpinfo() and there is not info about `pgsql`. What I must do also? I am missing something? – Oto Shavadze Jul 07 '13 at 21:12
  • `libpq.dll` and other dependencies must be in the PATH of apache's environment. – Daniel Vérité Jul 07 '13 at 21:21
  • Is the `php.ini` file you are talking about is the one loaded by PHP ? You can see that on the `phpinfo()` page. – greg Jul 09 '13 at 16:18

1 Answers1

-1

I too have tried to connect to a database using pg_connect but I am getting Error: call to undefined function. I have used PDO to connect to database. This seems to work.

<?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();
}
?>