Skip to content

Instantly share code, notes, and snippets.

@eMerzh
Created July 4, 2012 08:51
Show Gist options
  • Save eMerzh/3046155 to your computer and use it in GitHub Desktop.
Save eMerzh/3046155 to your computer and use it in GitHub Desktop.
Pg PDO test
<?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";
}
/***
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!
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment