php - Issue connecting to postgresql using pdo on localhost (08006) -
i have set test server , installed php 5.4 (zend server nginx) , postgresql 9.1.
i trying connect postgresql database using following code:
define('db_type', 'pgsql'); define('db_host', 'localhost'); define('db_port', 5432); define('db_name', 'rockprofile'); define('db_username', 'rockprofile'); define('db_password', 'password'); $dsn = db_type . ':dbname=' . db_name . ';host=' . db_host . ';port=' . db_port; try { $db = new pdo($dsn, db_username, db_password); } catch (pdoexception $e) { echo $e->getmessage(); print_r($e->gettrace()); }
however generating following:
sqlstate[08006] [7] fatal: ident authentication failed user "rockprofile" array ( [0] => array ( [file] => /usr/share/nginx/inc/config.php [line] => 24 [function] => __construct [class] => pdo [type] => -> [args] => array ( [0] => pgsql:dbname=rockprofile;host=localhost;port=5432 [1] => rockprofile [2] => password ) ) [1] => array ( [file] => /usr/share/nginx/bands/index.php [line] => 2 [args] => array ( [0] => /usr/share/nginx/inc/config.php ) [function] => include ) )
as can see using localhost. know dsn correct including username , password because if substitute localhost local 192 ip works. suspect issue configuration of postgresql , following current content:
local peer host 127.0.0.1/32 ident host ::1/128 ident host 192.168.1.0/24 md5
on searching appeared resolve changing ident trust on config above has not helped in case.
it simple need add searches seem fruitless @ moment. can tell me how correct this.
*-----edit-----*
as per daniel vérité's response fix issue ident needs changed md5. had change both ipv4 , ipv6 entries.
local peer host 127.0.0.1/32 md5 host ::1/128 md5 host 192.168.1.0/24 md5
see http://www.postgresql.org/docs/9.1/static/auth-methods.html:
the ident authentication method works obtaining client's operating system user name ident server , using allowed database user name (with optional user name mapping)
the ident
authentication method not suited connections web server, because web processes run under account, typically www-data
or such has no relationship databases account (rockprofile
in case).
since want authentication password, replace md5
in pg_hba.conf
, reload or restart postgresql.
also may change password because appears in clear in trace, negating substitution effort in code.
Comments
Post a Comment