Обсуждение: Help in connecting to a database with PHP

Поиск
Список
Период
Сортировка

Help in connecting to a database with PHP

От
"Michael J. McGillick"
Дата:

Hi:

 

I’m trying to learn how to set up a .php file to connect to my PostgreSQL database. From the command line, I can connect, open and work in the database on my machine. However, if I create a .php page with the following information:

 

   $db = pg_connect(“dbname=baseball user=postgres”);

 

I get the following error message:

 

   Warning: Unable to connect to PostgreSQL server: FATAL 1: IDENT authentication failed for user “postgres” in /var/www/html/baseball.php on line 10.

 

I’m running a stock Red Hat Linux 7.3 machine with PostgreSQL version 7.2. I have verified that from the command line, I can switch to the user postgres and connect to the database with no problems. I can view data, add and delete records, etc.

 

I’d appreciate some help in trying to track down what I’m doing wrong. I’ve spent the past few days looking at documentation from various web sites, and nothing seems to jump out as the culprit.

 

- Michael

Re: Help in connecting to a database with PHP

От
Ludwig Lim
Дата:
Hi:

--- "Michael J. McGillick" <mmcgillick@attbi.com>
wrote:
> Hi:
>
>
>
> I'm trying to learn how to set up a .php file to
> connect to my
> PostgreSQL database. From the command line, I can
> connect, open and work
> in the database on my machine. However, if I create
> a .php page with the
> following information:
>
>
>
>    $db = pg_connect("dbname=baseball
> user=postgres");
>
>
>
> I get the following error message:
>
>
>
>    Warning: Unable to connect to PostgreSQL server:
> FATAL 1: IDENT
> authentication failed for user "postgres" in
> /var/www/html/baseball.php
> on line 10.

  Try checking the file "pg_hba.conf" ( Usually in
/usr/local/pgsql/data). It seems that your connection
requires a password. try to set the "auth_type" to
"trust" in "pg_hba.conf" to skip password check or use
"pg_connect(dbname=baseball user=postgres
password=<password of the user account "postgres");"

Hope that helps.

ludwig.

__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

Re: Help in connecting to a database with PHP

От
Eckhard Hoeffner
Дата:
* Michael J. McGillick <mmcgillick@attbi.com> [27 05 02 08:07]:

>Hi:
>
>
>
>I'm trying to learn how to set up a .php file to connect to my
>PostgreSQL database. From the command line, I can connect, open and work
>in the database on my machine. However, if I create a .php page with the
>following information:
>
>
>
>   $db = pg_connect("dbname=baseball user=postgres");
>
>
>
>I get the following error message:

If you are accessing the database via a web server, you should allow
TCP/IP connections. (postmaster -i)

>   Warning: Unable to connect to PostgreSQL server: FATAL 1: IDENT
>authentication failed for user "postgres" in /var/www/html/baseball.php
>on line 10.
This looks like a socket connection, not TCP/IP.
>
>
>I'm running a stock Red Hat Linux 7.3 machine with PostgreSQL version
>7.2. I have verified that from the command line, I can switch to the
>user postgres and connect to the database with no problems. I can view
>data, add and delete records, etc.
>
>
>
>I'd appreciate some help in trying to track down what I'm doing wrong.
>I've spent the past few days looking at documentation from various web
>sites, and nothing seems to jump out as the culprit.
>
>
>
>- Michael
>

--
--//--\\--
Eckhard Hoeffner
e-hoeffner@fifoost.org
Tal 44
D-80331 München