2

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 ?

2
  • 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. Feb 20, 2011 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, 2011 at 12:45

1 Answer 1

2

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 :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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