I try to connect to a remote MySQL database using PDO, but the error fails:
Connection failed: SQLSTATE[28000] [1045] Access denied for user 'my_user'@'some.ip.address' (using password: YES)
This is how I try to connect:
$dsn = "mysql:host=sql.my_domain.nazwa.pl;dbname=my_db;port:3307"; $user = "my_user"; $password = "my_password"; try { $this->db = new PDO($dsn, $user, $password); } catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); }
and he fails. But:
mysql_connect('sql.my_domain.nazwa.pl:3307', 'my_user', 'my_password');
works great.
Does anyone know what might be wrong with the PDO, its configuration, the parameters I set, or maybe this particular server (nazwa.pl)?
[SOLVED] Okay, so this was a simple (but also complicated to notice ...) syntax error, it should be = instead : in the port part of dsn .
source share