Page 1 of 1

php errors

Posted: Mon Apr 07, 2003 5:04 am
by Love_Daddy
I've written a code to test postgres in php and I get the following errors

Warning: pg_connect() unable to connect to PostgreSQL server: FATAL 1: user "apache" does not exist in /var/www/html/testdb.php on line 2

Warning: pg_exec(): supplied argument is not a valid PostgreSQL link resource in /var/www/html/testdb.php on line 4
There's been an error

and my code:

<?php
$conn=pg_connect("dbname =mobiledb");
$sql = "select * from users";
$result = pg_exec($conn,$sql);
if (!$result) {printf("There's been an error");exit;}
$row=pg_fetch_row($result,0);
printf("Phone number:%s<br>\n",$row[1]);
printf("Service Provider:%s<br>\n",$row[2]);
pg_close();
?>

What am I doing wrong?

Posted: Mon Apr 07, 2003 5:08 am
by d1223m
im not a postgres user but to me it looks like your connection to postgres and giving no username or password - therefore its using the user that your httpd runs as ie. apache.
you need to create a user in postgres with the username "apache" and no password or actually give it one.

Posted: Mon Apr 07, 2003 8:41 am
by volka
or use a valid account for the database
http://www.php.net/manual/en/function.pg-connect.php wrote:$dbconn3 = pg_connect ("host=sheep port=5432 dbname=mary user=lamb password=foo");

My error

Posted: Mon Apr 07, 2003 9:28 am
by Love_Daddy
Hi all,

I managed to figure the problem out.
All I needed to do was to create apache as a user and it worked fine.

Posted: Mon Apr 07, 2003 10:14 am
by d1223m
you need to create a user in postgres with the username "apache"
/me awards /me a gold star


:wink: