Обсуждение: Problems in connecting to postgreSQL using PHP

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

Problems in connecting to postgreSQL using PHP

От
"Kitty Yuen"
Дата:
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?
 
Many thanks,
Kitty3A 

Re: Problems in connecting to postgreSQL using PHP

От
Matthew Terenzio
Дата:
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?
>  
> Many thanks,
> Kitty3A 


Re: Problems in connecting to postgreSQL using PHP

От
Thomas Schindler
Дата:
how do i get off this list?

On Mar 12, 2007, at 12:35 PM, 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?
>>
>> Many thanks,
>> Kitty3A
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster

--
Thomas Schindler . Geschäftsführer
hundertelf GmbH . HRB 52839
Philippstraße 6 . 50823 Köln
fon +49 (0)221 - 5897566
cel +49 (0)162 - 9034568
fax +49 (0)221 - 35569618
thomas.schindler@hundertelf.com
www.hundertelf.com





Вложения

Re: Problems in connecting to postgreSQL using PHP

От
"Valentín Orfila"
Дата:
Hi!!! I'm Venezuelan and I don't know how to speak english very well, so excuse me if i make a mistake.

About the connection: Did you do your script by yourself?, or copied a functional one?

As Thomas Schindler said, send us any PHP errors or the pg_hba.conf ?

Here is my connection script, it is completly good check it out to see if you have anything wrong

<?  /*---------------*/
    $servidor = "localhost";
     $base = "databasename"; //change it
     $usuario = "postgresuser"; //change it
     $password = "postgresuser"; //change it
  
     pg_pconnect("host=$servidor dbname=$base user=$usuario password=$password");
  
?>

That's all what I can do for now

2007/3/12, Matthew Terenzio <matt@jobsforge.com>:
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


---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster



--
***************************************************************************
Ministerio de Planificación y Desarrollo de la República Bolivariana de Venezuela
Dirección de Planes de Personal

José Valentín Orfila Briceño
Programador II

Teléfonos: Celular: (0416) 4131418

E-mail: valentinorfila@gmail.com
           valentinorfila@hotmail.com
           josevalentinorfila@yahoo.com

Messenger: valentinorfila@hotmail.com

Skype: valentinorfila
           valentinorfila@gmail.com
***************************************************************************

Re: Problems in connecting to postgreSQL using PHP

От
"Valentín Orfila"
Дата:
here is the script again

<?  /*---------------*/
    $servidor = "localhost";
     $base = "databasename"; //change it
     $usuario = "postgresuser"; //change it
     $password = "postgresuserpassword"; //change it
  
     pg_pconnect("host=$servidor dbname=$base user=$usuario password=$password");
  
?>

2007/3/12, Valentín Orfila <valentinorfila@gmail.com>:
Hi!!! I'm Venezuelan and I don't know how to speak english very well, so excuse me if i make a mistake.

About the connection: Did you do your script by yourself?, or copied a functional one?

As Thomas Schindler said, send us any PHP errors or the pg_hba.conf ?

Here is my connection script, it is completly good check it out to see if you have anything wrong

<?  /*---------------*/
    $servidor = "localhost";
     $base = "databasename"; //change it
     $usuario = "postgresuser"; //change it
     $password = "postgresuser"; //change it
  
     pg_pconnect("host=$servidor dbname=$base user=$usuario password=$password");
  
?>

That's all what I can do for now

2007/3/12, Matthew Terenzio < matt@jobsforge.com>:
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


---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster



--
***************************************************************************
Ministerio de Planificación y Desarrollo de la República Bolivariana de Venezuela
Dirección de Planes de Personal

José Valentín Orfila Briceño
Programador II

Teléfonos: Celular: (0416) 4131418

E-mail: valentinorfila@gmail.com
           valentinorfila@hotmail.com
           josevalentinorfila@yahoo.com

Messenger: valentinorfila@hotmail.com

Skype: valentinorfila
           valentinorfila@gmail.com
***************************************************************************



--
***************************************************************************
Ministerio de Planificación y Desarrollo de la República Bolivariana de Venezuela
Dirección de Planes de Personal

José Valentín Orfila Briceño
Programador II

Teléfonos: Celular: (0416) 4131418

E-mail: valentinorfila@gmail.com
           valentinorfila@hotmail.com
           josevalentinorfila@yahoo.com

Messenger: valentinorfila@hotmail.com

Skype: valentinorfila
           valentinorfila@gmail.com
***************************************************************************

Re: Problems in connecting to postgreSQL using PHP

От
Chris
Дата:
Thomas Schindler wrote:
> how do i get off this list?

Find where you subscribed and choose the unsubscribe option?

Click the unsubscribe link that appears randomly in the footers?

Or even follow the links in the email headers included with every email.

List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-php>

--
Postgresql & php tutorials
http://www.designmagick.com/

Re: Problems in connecting to postgreSQL using PHP

От
"Kitty Yuen"
Дата:
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


Re: Problems in connecting to postgreSQL using PHP

От
"Kitty Yuen"
Дата:
Dear Valentín,

I think I have already enabled the extension and found the extension in my pgsql.ini file in php.d folder. However, I still cannot connect to the database. I guess I have something to be config in the PostgreSQL. Do you have any ideas?


Kitty3a

On 3/13/07, Valentín Orfila <valentinorfila@gmail.com> wrote:
OK. Now you have to activate the library to connect PHP to PostgreSQL, this is in the php.ini file. In Windows 2000 it is in the following folders: C:\WINNT and in the PHP installation folder, in my case: C:\AppServ\php. Once you find this file you have to discomment this extension: extension=php_pgsql.dll, to do that you are going to erase the ";" at the beggining of the line.

Look for this file (php.ini) in your O.S. and configured it. If you are using Linux I guess it is in the etc/profile/php.config directory, but I0m not sure.

I'm attaching you my file:


2007/3/12, Kitty Yuen <kitty3a@gmail.com>:
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





--
***************************************************************************
Ministerio de Planificación y Desarrollo de la República Bolivariana de Venezuela
Dirección de Planes de Personal

José Valentín Orfila Briceño
Programador II

Teléfonos: Celular: (0416) 4131418

E-mail: valentinorfila@gmail.com
           valentinorfila@hotmail.com
           josevalentinorfila@yahoo.com

Messenger: valentinorfila@hotmail.com

Skype: valentinorfila
           valentinorfila@gmail.com
***************************************************************************


Re: Problems in connecting to postgreSQL using PHP

От
"Valentín Orfila"
Дата:
Kitty,

Try try using this function: pg_pconnect("host=$servidor dbname=$base user=$usuario password=$password");, I mean, use the connection script I'm going to paste below.

<?  /*---------------*/
    $servidor = "localhost";
     $base = "databasename"; //change it
     $usuario = "postgresuser"; //change it
     $password = "postgresuserpassword"; //change it
  
     pg_pconnect("host=$servidor dbname=$base user=$usuario password=$password");
  
?>



2007/3/12, Valentín Orfila <valentinorfila@gmail.com>:
here is the script again

<?  /*---------------*/
    $servidor = "localhost";
     $base = "databasename"; //change it
     $usuario = "postgresuser"; //change it
     $password = "postgresuserpassword"; //change it
  
     pg_pconnect("host=$servidor dbname=$base user=$usuario password=$password");
  
?>

2007/3/12, Valentín Orfila <valentinorfila@gmail.com >:
Hi!!! I'm Venezuelan and I don't know how to speak english very well, so excuse me if i make a mistake.

About the connection: Did you do your script by yourself?, or copied a functional one?

As Thomas Schindler said, send us any PHP errors or the pg_hba.conf ?

Here is my connection script, it is completly good check it out to see if you have anything wrong

<?  /*---------------*/
    $servidor = "localhost";
     $base = "databasename"; //change it
     $usuario = "postgresuser"; //change it
     $password = "postgresuser"; //change it
  
     pg_pconnect("host=$servidor dbname=$base user=$usuario password=$password");
  
?>

That's all what I can do for now

2007/3/12, Matthew Terenzio < matt@jobsforge.com>:
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


---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster



--
***************************************************************************
Ministerio de Planificación y Desarrollo de la República Bolivariana de Venezuela
Dirección de Planes de Personal

José Valentín Orfila Briceño
Programador II

Teléfonos: Celular: (0416) 4131418

E-mail: valentinorfila@gmail.com
           valentinorfila@hotmail.com
           josevalentinorfila@yahoo.com

Messenger: valentinorfila@hotmail.com

Skype: valentinorfila
           valentinorfila@gmail.com
***************************************************************************



--
***************************************************************************
Ministerio de Planificación y Desarrollo de la República Bolivariana de Venezuela
Dirección de Planes de Personal

José Valentín Orfila Briceño
Programador II

Teléfonos: Celular: (0416) 4131418

E-mail: valentinorfila@gmail.com
           valentinorfila@hotmail.com
           josevalentinorfila@yahoo.com

Messenger: valentinorfila@hotmail.com

Skype: valentinorfila
           valentinorfila@gmail.com
***************************************************************************



--
***************************************************************************
Ministerio de Planificación y Desarrollo de la República Bolivariana de Venezuela
Dirección de Planes de Personal

José Valentín Orfila Briceño
Programador II

Teléfonos: Celular: (0416) 4131418

E-mail: valentinorfila@gmail.com
           valentinorfila@hotmail.com
           josevalentinorfila@yahoo.com

Messenger: valentinorfila@hotmail.com

Skype: valentinorfila
           valentinorfila@gmail.com
***************************************************************************

Re: Problems in connecting to postgreSQL using PHP

От
"Valentín Orfila"
Дата:
I already told you all I thought, but...

Below is the local config in my pg_hba and i just see you have one line more than me, do you use Unix? if not, so erase that line and try again

# TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD

# IPv4 local connections:
host    all         all         127.0.0.1/32            trust

# IPv6 local connections:
localhost    all         all         ::1/128               trust




2007/3/13, Kitty Yuen <kitty3a@gmail.com>:
Dear Valentín,

I think I have already enabled the extension and found the extension in my pgsql.ini file in php.d folder. However, I still cannot connect to the database. I guess I have something to be config in the PostgreSQL. Do you have any ideas?


Kitty3a

On 3/13/07, Valentín Orfila < valentinorfila@gmail.com> wrote:
OK. Now you have to activate the library to connect PHP to PostgreSQL, this is in the php.ini file. In Windows 2000 it is in the following folders: C:\WINNT and in the PHP installation folder, in my case: C:\AppServ\php. Once you find this file you have to discomment this extension: extension=php_pgsql.dll, to do that you are going to erase the ";" at the beggining of the line.

Look for this file (php.ini) in your O.S. and configured it. If you are using Linux I guess it is in the etc/profile/php.config directory, but I0m not sure.

I'm attaching you my file:


2007/3/12, Kitty Yuen <kitty3a@gmail.com>:
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





--
***************************************************************************
Ministerio de Planificación y Desarrollo de la República Bolivariana de Venezuela
Dirección de Planes de Personal

José Valentín Orfila Briceño
Programador II

Teléfonos: Celular: (0416) 4131418

E-mail: valentinorfila@gmail.com
           valentinorfila@hotmail.com
           josevalentinorfila@yahoo.com

Messenger: valentinorfila@hotmail.com

Skype: valentinorfila
           valentinorfila@gmail.com
***************************************************************************





--
***************************************************************************
Ministerio de Planificación y Desarrollo de la República Bolivariana de Venezuela
Dirección de Planes de Personal

José Valentín Orfila Briceño
Programador II

Teléfonos: Celular: (0416) 4131418

E-mail: valentinorfila@gmail.com
           valentinorfila@hotmail.com
           josevalentinorfila@yahoo.com

Messenger: valentinorfila@hotmail.com

Skype: valentinorfila
           valentinorfila@gmail.com
***************************************************************************