Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id D6FA39FB2DA for ; Mon, 12 Mar 2007 23:27:20 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 07919-07 for ; Mon, 12 Mar 2007 23:27:16 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.184]) by postgresql.org (Postfix) with ESMTP id E2F4D9FA188 for ; Mon, 12 Mar 2007 23:27:15 -0300 (ADT) Received: by nf-out-0910.google.com with SMTP id x4so2312897nfb for ; Mon, 12 Mar 2007 19:27:14 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=HShx8nTC2yKWiVZbLqD++Q8wck+78f8Z8lvePjUtuJ2MyAkYB1ljQtMzTFC2oKDMPbB5ZYwgLOeQG0Whnb4K252CXaLiunb5hfINro9ebifc+yiUswq/VxSw22IpdsVvyJQnZOeQYfc3HuV1TveEAgH3AlTWUDa++dSYhzVbPBw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=RBBaiAdXlNz7cAB2Fk+u3EtbyC4TQUI6JEjnWSmUeopnYkDwnRRmv+b1ch+L3B4CiTvu7VUzKETT9sPJii91LVvPdx3iEAnBASbP54uA0o5QbKeLlUcR+ngDhOtHShpLKrusY5Kicv8NSY4PmY6kbFgJ0jeF7wCMc1i3SrIfdb8= Received: by 10.114.133.1 with SMTP id g1mr2196258wad.1173752833154; Mon, 12 Mar 2007 19:27:13 -0700 (PDT) Received: by 10.114.152.10 with HTTP; Mon, 12 Mar 2007 19:27:13 -0700 (PDT) Message-ID: Date: Tue, 13 Mar 2007 10:27:13 +0800 From: "Kitty Yuen" To: "Matthew Terenzio" Subject: Re: Problems in connecting to postgreSQL using PHP Cc: pgsql-php@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_18150_5808283.1173752833101" References: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200703/41 X-Sequence-Number: 3753 ------=_Part_18150_5808283.1173752833101 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Here are my error messages from PHP: [Mon Mar 12 16:01:26 2007] [error] [client 127.0.0.1] PHP Warning: pg_connect() [function.pg-connect]: Unable to connect to PostgreSQL server: could not connect to server: Permission denied\n\tIs the server running locally and accepting\n\tconnections on Unix domain socket "/tmp/.s.PGSQL.5432"? in /var/www/html/try.php on line 3 [Mon Mar 12 16:01:26 2007] [error] [client 127.0.0.1] PHP Warning: pg_last_error() [function.pg-last-error]: No PostgreSQL link opened yet in /var/www/html/try.php on line 4 PHP Code: \n"; while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) { echo "\t\n"; foreach ($line as $col_value) { echo "\t\t$col_value\n"; } echo "\t\n"; } echo "\n"; // Free resultset pg_free_result($result); // Closing connection pg_close($dbconn); *pg_hba.cof* # TYPE DATABASE USER CIDR-ADDRESS METHOD # "local" is for Unix domain socket connections only local all all trust # IPv4 local connections: host all all 127.0.0.1/32 trust # IPv6 local connections: host all all ::1/128 trust *postgresql.conf* #--------------------------------------------------------------------------- # CONNECTIONS AND AUTHENTICATION #--------------------------------------------------------------------------- # - Connection Settings - listen_addresses = 'localhost' # what IP address(es) to listen on; # comma-separated list of addresses; # defaults to 'localhost', '*' = all port = 5432 max_connections = 100 # note: increasing max_connections costs ~400 bytes of shared memory per # connection slot, plus lock space (see max_locks_per_transaction). You # might also need to raise shared_buffers to support more connections. superuser_reserved_connections = 2 unix_socket_directory = '' unix_socket_group = '' unix_socket_permissions = 0777 # octal bonjour_name = '' # defaults to the computer name Thanks a lot, Kitty3A On 3/12/07, Matthew Terenzio wrote: > > Could you provide any PHP errors or the pg_hba.conf ? > > On Mar 12, 2007, at 12:25 AM, Kitty Yuen wrote: > > > Hi, > > > > I am trying to connect my postgreSQL with PHP in localhost. I have > > start up the server with -i flag (i.e. postmaster -D > > /usr/local/pgsql/data -i &) and edit the pg_hba.conf. However, I still > > cannot connect with the database. But, when I tried to remote access > > the database through SSH and I can connect with it. > > > > Would you please offer any suggestions or solutions? > > > > Manythanks, > > Kitty3A > > ------=_Part_18150_5808283.1173752833101 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline
Here are my error messages from PHP:
 

[Mon Mar 12 16:01:26 2007] [error] [client 127.0.0.1] PHP Warning:   pg_connect() [<a href='function.pg-connect'>function.pg-connect</a>]: Unable to connect to PostgreSQL server: could not connect to server: Permission denied\n\tIs the server running locally and accepting\n\tconnections on Unix domain socket &quot;/tmp/.s.PGSQL.5432&quot;? in /var/www/html/try.php on line 3

[Mon Mar 12 16:01:26 2007] [error] [client 127.0.0.1] PHP Warning:   pg_last_error() [<a href='function.pg-last-error'>function.pg-last-error</a>]: No PostgreSQL link opened yet in /var/www/html/try.php on line 4

 
PHP Code:
 

<?php

// Connecting, selecting database

$dbconn = pg_connect("dbname=test user=postgres")

   or die('Could not connect: ' . pg_last_error());

 

// Performing SQL query

$query = 'SELECT * FROM haha';

$result = pg_query($query) or die('Query failed: ' . pg_last_error());

 

// Printing results in HTML

echo "<table>\n";

while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {

   echo "\t<tr>\n";

   foreach ($line as $col_value) {

       echo "\t\t<td>$col_value</td>\n";

   }

   echo "\t</tr>\n";

}

echo "</table>\n";

 

// Free resultset

pg_free_result($result);

 

// Closing connection

pg_close($dbconn);

 

pg_hba.cof

# TYPE  DATABASE    USER         CIDR-ADDRESS          METHOD

 

# "local" is for Unix domain socket connections only

local   all         all                                trust

 

# IPv4 local connections:

host    all         all          127.0.0.1/32          trust

# IPv6 local connections:

host    all         all          ::1/128               trust

 
postgresql.conf
 

#---------------------------------------------------------------------------

# CONNECTIONS AND AUTHENTICATION

#---------------------------------------------------------------------------

 

# - Connection Settings -

 

listen_addresses = 'localhost'             # what IP address(es) to listen on;

                                        # comma-separated list of addresses;

                                        # defaults to 'localhost', '*' = all

port = 5432

max_connections = 100

# note: increasing max_connections costs ~400 bytes of shared memory per

# connection slot, plus lock space (see max_locks_per_transaction).  You

# might also need to raise shared_buffers to support more connections.

superuser_reserved_connections = 2

unix_socket_directory = ''

unix_socket_group = ''

unix_socket_permissions = 0777              # octal

bonjour_name = ''                     # defaults to the computer name
 
Thanks a lot,
Kitty3A
 
 
 
 

 
On 3/12/07, Matthew Terenzio <matt@jobsforge.com> wrote:
Could you provide any PHP errors or the pg_hba.conf ?

On Mar 12, 2007, at 12:25 AM, Kitty Yuen wrote:

> Hi,
>
> I am trying to connect my postgreSQL with PHP in localhost. I have
> start up the server with -i flag (i.e. postmaster -D
> /usr/local/pgsql/data -i &) and edit the pg_hba.conf. However, I still
> cannot connect with the database. But, when I tried to remote access
> the database through SSH and I can connect with it.
>
> Would you please offer any suggestions or solutions?
>
> Manythanks,
> Kitty3A


------=_Part_18150_5808283.1173752833101--