Re: [PHP] works at command line but not in apache

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

Re: [PHP] works at command line but not in apache

От:
Bob Hartung <rwhart@mchsi.com>
Дата:
Thanks, but I have these changes in and it still will not connect:
file:  pg_hba.conf:
# IPv4 local connections:
host    all         all         127.0.0.1/32          ident sameuser

postgrsql.conf:
   listen_addresses = 'localhost'	
   port = 5432

It is my understanding that the current version 8.1+ now uses the
generalized 'listen_addresses' in postgresql.conf instead of any tcp* =
'true' statements in this file.

I also am assuming that the postgresql.conf file being read is that in
the /var/lib/pgsql/data directory.

I am connecting to localhost, need to make sure I can configure for
tcpip, and am trying to login as a local user with a user account on the
machine.

Other ideas?  I am not having much luck finding more in the docs.

TIA

Bob


Tijnema ! wrote:
> On 3/17/07, rwhartung  wrote:
>> Hi,
>>   I have this short php script: [op;ening  removed.
>>
>>
>> $db = pg_connect('dbname=bpsimple user=minitwr password=RWHart') ;
> 
>> print $db . "
" . "\n" ; >> if ($db) >> { >> print 'Connection attempt succeeded.' . "
" . "\n" ; >> } else >> { >> print 'Connection attempt failed.'. "
" . "\n" ; >> } >> >> $query = 'SELECT fname, lname FROM customer' ; >> $result = pg_query($db, $query) ; >> while($myrow = pg_fetch_assoc($result) ) >> { >> print $myrow['fname'] . " " . $myrow['lname'] . "\n" ; >> } >> >> This works fine as a PHP script from the command line, but wrapped up in >> tags it refuses to connect with the database from within >> apache. All connections are local host. PHP otherwise works fine on >> the apache server and the code is identical on both the CL script and >> the test.php web page. Ideas? Where to start looking? >> >> TIA >> >> Bob > > One of the comments in the PHP Manual says this: > > If you use pg_connect('host=localhost port=5432 user=my_username > password=my_password dbname=my_dbname') and you get the following > error: > "Warning: pg_connect(): Unable to connect to PostgreSQL server: could > not connect to server: Connection refused Is the server running on > host localhost and accepting TCP/IP connections on port 5432?" > then you should try to leave the host= and port= parts out of the > connection string. This sounds strange, but this is an "option" of > Postgre. If you have not activated the TCP/IP port in postgresql.conf > then postgresql doesn't accept any incoming requests from an TCP/IP > port. If you use host= in your connection string you are going to > connect to Postgre via TCP/IP, so that's not going to work. If you > leave the host= part out of your connection string you connect to > Postgre via the Unix domain sockets, which is faster and more secure, > but you can't connect with the database via any other PC as the > localhost. > > I think that's what your problem is also, but not sure about it. > (using MySQL mostly) > > Tijnema >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> >

Re: [PHP] works at command line but not in apache

От:
Alvaro Herrera <alvherre@commandprompt.com>
Дата:
Bob Hartung wrote:
> Thanks, but I have these changes in and it still will not connect:
> file:  pg_hba.conf:
> # IPv4 local connections:
> host    all         all         127.0.0.1/32          ident sameuser

He also wrote:
> >>$db = pg_connect('dbname=bpsimple user=minitwr password=RWHart') ;


The connection string you showed before will not match a "host" entry in
pg_hba.conf.  You need to have a "local" entry, which I think is
something that goes like

local	all	all		ident sameuser

Please check the documentation.

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
FAQ