Re: works at command line but not in apache
| From: | Jim Lucas | Date: | Sun, 18 Mar 2007 09:32:54 +0000 |
| Subject: | Re: works at command line but not in apache | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-250773@lists.php.net to get a copy of this message | ||
Tijnema ! wrote:
On 3/18/07, rwhartung <rwhartung@rgimaging.com> wrote:if you think it is the pg_connect() call that is causing problems, then do this. It is crude way to debug, but it will work. $db = pg_connect('host=localhost port=5432 dbname=bpsimple user=minitwr password=RWHart') or die('error' . pg_last_error()); if the pg_connect is causing the error, then this should give you a clue as to where the problem it.Thanks, but I have these changes in and it still will not connect: file: pg_hba.conf: # IPv4 local connections:So, you want it to run through TCP/IP, then you need to add the host=localhost and port=5432 items to your pg_connect string $db = pg_connect('dbname=bpsimple user=minitwr password=RWHart') ; becomes: $db = pg_connect('host=localhost port=5432 dbname=bpsimple user=minitwr password=RWHart') ;host all all 127.0.0.1/32 ident sameuserpostgrsql.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 <rwhartung@rgimaging.com> wrote:removed.Hi, I have this short php script: [op;ening <?php and closing ?>$db = pg_connect('dbname=bpsimple user=minitwr password=RWHart') ;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) Tijnemaup inprint $db . "<br />" . "\n" ; if ($db) {print 'Connection attempt succeeded.' . "<br />" . "\n" ;} else {print 'Connection attempt failed.'. "<br />" . "\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 wrappedwithin<html> </html> tags it refuses to connect with the database fromapache. 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-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php