Closed
Description
Description
The following code:
<?php
/*
correct credentials
user: p_user
pass: p_pass
*/
$db = new PDO(
'pgsql:host=<host>;port=5432;dbname=db;user=p_user;password=p_pass', // my env
'hoge',
'fuga'
);
Resulted in this output:
// Connects to DB without any errors
But I expected this output instead:
Fatal error: Uncaught PDOException: SQLSTATE[08006] [7] connection to server at "<host>" (<host IP>), port 5432 failed: FATAL: no pg_hba.conf entry for host "<client IP>", user "hoge", database "db", SSL encryption
connection to server at "<host>" (<host IP>), port 5432 failed: FATAL: no pg_hba.conf entry for host "<client IP>", user "hoge", database "db", no encryption in <path to file>:8
Stack trace:
#0 <path to file>(8): PDO->__construct('pgsql:host=<host>.....', 'hoge', Object(SensitiveParameterValue))
#1 {main}
thrown in <path to file> on line 8
This result means that if both the DSN and the argument are given different credentials, the DSN's credentials are ignored and the argument's credentials are used.
This behavior differs from what is described in the documentation.
https://www.php.net/manual/en/ref.pdo-pgsql.connection.php
Also, pdo_odbc
can similarly pass credentials to both DSN and arguments, but pdo_odbc gives priority to DSN. Based on these things, I think that the behavior of pdo_pgsql
should be modified.
PHP Version
At least php5.6+
Operating System
any