php errors

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Love_Daddy
Forum Commoner
Posts: 61
Joined: Wed Jul 10, 2002 6:55 am
Location: South Africa
Contact:

php errors

Post 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?
User avatar
d1223m
Forum Commoner
Posts: 80
Joined: Mon Mar 31, 2003 5:15 am
Location: UK, West Sussex

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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");
User avatar
Love_Daddy
Forum Commoner
Posts: 61
Joined: Wed Jul 10, 2002 6:55 am
Location: South Africa
Contact:

My error

Post 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.
User avatar
d1223m
Forum Commoner
Posts: 80
Joined: Mon Mar 31, 2003 5:15 am
Location: UK, West Sussex

Post by d1223m »

you need to create a user in postgres with the username "apache"
/me awards /me a gold star


:wink:
Post Reply