Cannot connect to postgreSQL database via php pdo driver

I decided to switch from MySQL to PostgreSQL recently, mostly just to learn a new DB. It was pretty painful, but I think I'm close.

I use php and PDO, my PDO driver has been successfully installed and configured.

Opening my site, I get an error message:

Connection failed: SQLSTATE[08006] [7] FATAL: Ident authentication failed for user "postgres" 

I use the following connection calls (I tried several options for calling user / pw in the $ dsn variable and in the separate $ user / $ pass variables, including port = 5432):

 $dsn = 'pgsql:dbname=db1;host=localhost;user=postgres;password=pass'; $db = new PDO($dsn); 

Alternatively, I can enter my db from the command line:

 $ su postgres 

(pass)

 $ psql db1 

output:

failed to change directory to "/ home / ec2-user" psql (8.4.9) Type "help" for help.

DB1 = #

Any ideas? I would like to provide additional information if necessary.

+4
source share
1 answer

Is your pg_hba.conf file correct? This is a well-known source of pain in the beginning with PostgreSQL. And the situation you mention is a good candidate for such a problem. :-)

+6
source

Source: https://habr.com/ru/post/1379573/


All Articles