Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I've recently experimented with the settings in pg_hba.conf. I read the PostgreSQL documentation and I though that the "password" auth method is what I want. There are many people that have access to the server PostgreSQL is working on so I don't want the "trust" method. So I changed it. But then PHP stopped working with the database.

The message I get is "Warning: pg_connect(): Unable to connect to PostgreSQL server: FATAL: password authentication failed for user "myuser" in /my/path/to/connection/class.php on line 35". It is kind of strange because I can connect via phppgadmin without any problems and also I can connect from my home computer with psql - again without any problems.

This is my pg_hba.conf:

# TYPE  DATABASE        USER            CIDR-ADDRESS            METHOD
# "local" is for Unix domain socket connections only
local   all             all                                     password
# IPv4 local connections:
host    all             all             127.0.0.1/32            password
# IPv6 local connections:
host    all             all             ::1/128                 password

The connection string I'm using with pg_conenct is:

$connect_string = "host=localhost port=5432 dbname=mydbname user=auser password=apassword";
$dbConnection = pg_connect($connection_string);

Does anybody know why is this happening ? Did I misconfigured something ?

share|improve this question
3  
Probably not the reason for your problem, but you really shouldn't be using the "password" method. You should be using "md5" if you want username/password combinations. –  Magnus Hagander Feb 20 '11 at 10:05
    
Thanks Magnus :) I'll have that in mind. At first it was md5 but I thought it may be because of the encryption and after that I changed it to password.. No result thought... :) –  tftd Feb 20 '11 at 12:45

1 Answer 1

It appears that when you have password that contains slashes (\ /) you need to escape them in the pg_connect connection url. After escaping that I had no problems connecting to the database via php. Hope this helps somebody having this problem :)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.