This forum is no longer active. Please post your questions to our new community site

Forums MAPPStack

using pg_connect

Subscribe to using pg_connect 2 post(s), 2 voice(s)

 
Avatar subregi 1 post

Hi,

I am trying to write a simple php program to connect to an existing pg database.
I am using mappstack 1.2.1 on os-x intel 10.5.8
PHP and Postgres work fine independently.
Even PGAdmin3 client app connects to my db and runs fine.
But when I write a minimal php script to access the postgres db, it fails with pg_connect with the error

PHP Warning: pg_connect(): Unable to connect to PostgreSQL server: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket “/tmp/.s.PGSQL.5500”?
No PostgreSQL link opened yet in …./new.php on line 8

My code is the following:

<?php
$link = pg_connect(“dbname=postgres user=postgres password=xxxxx port=5500”);
if (!$link)
{
echo(“Connection failed.\n”);
die("Error in connection: " . pg_last_error());
exit;
}
?>

Can someone help me out?

Thanks
PGFan

 
Avatar carlos Administrator 144 post(s)

Hi,

You should modify the path to the socket using ‘host’ option. The Stack doesn’t use default socket location ( /tmp/.s.PGSQL* ) but <installdir>/postgresql

You can try using something similar to this:

pg_connect("host=<installdir>/postgresql user=username password=xxxx  dbname=postgres")

I hope it helps

Forums MAPPStack