I am making a PHP website with PDO with PHP, but my DSN (for Postgresql) does not connect to the database, and Mysql is working fine.
I am trying with the password abc .
Error: a PDOException exception with the message "SQLSTATE [08006] [7] is missing" = "after" b "in the connection information line in / var / www / owncloud / pg _test.php: 11
Stack trace:
# 0 / var / www / owncloud / pg_test.php (11): PDO → __ construct ('pgsql: dbname = te ...', 'test', 'ab c')
# 1 {main}
it works!
Code example :
<?php $dsn = "pgsql:dbname=test;host=localhost"; $user = "test"; $psw = "abc"; 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 working!\n"; }catch(PDOException $e){ echo "Error :" . $e."\n"; }
user1815798
source share