On 3/17/07, rwhartung <rwhartung@xxxxxxxxxxxxx> wrote:
Hi, I have this short php script: [op;ening <?php and closing ?> removed. $db = pg_connect('dbname=bpsimple user=minitwr password=RWHart') ;
print $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 wrapped up in <html> </html> 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
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php