public
Created

Pg PDO test

  • Download Gist
pdo_test.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
<?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!
*/

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.