I am making a PHP website using PDO with PHP but my DSN (for Postgresql) isn’t connecting to the database while with Mysql is working fine.
I am trying with the password a b c.
Error: exception ‘PDOException’ with message ‘SQLSTATE[08006] [7] missing “=” after “b” in connection info string’ in /var/www/owncloud/pg_test.php:11
Stack trace:
#0 /var/www/owncloud/pg_test.php(11): PDO->__construct(‘pgsql:dbname=te…’, ‘test’, ‘a b c’)
#1 {main}
it’s working!
<?php
/** createuser -d -R -S -P test
* => set password to "a b c"
*/
$dsn = "pgsql:dbname=test;host=localhost";
$user = "test";
$psw = "a b c";
try{
$db = new PDO($dsn,$user,$psw);
echo "Oh gosh!\n";
}catch(PDOException $e){
echo "Error :" . $e."\n";
}
$e_user = addslashes($user);
$e_password = addslashes($psw);
$psw = $user = null;
$dsn .= ";user='$e_user';password='$e_password'";
try{
$db = new PDO($dsn,$user,$psw);
echo "it's working!\n";
}catch(PDOException $e){
echo "Error :" . $e."\n";
}
This a bug in php ( no Bug #62479) that When you try to connect to a Postgresql database with a password containing 1 or more spaces, pdo will fail to connect
you have to use like
goget2me(No space in password )