This is a very old question, but I had the exact same issue and wanted to document it here for anyone who finds this later.
- You can connect to your database (Amazon RDS) manually from the command line.
- You can connect to your database via mysqli in PHP.
- You can not connect to your database via PDO in PHP.
For me, after trying almost everything, I randomly decided to try and create a new database user. This worked and I was now able to connect via PDO.
This prompted me to investigate the issue a little further and I was able to narrow the issue down to a backslash
\ character in my MySQL password.
There seems to be some kind of conflict between ENV Vars (with
\), PHP and PDO.
$db_host = "username.xxx.ap-xxx.rds.amazonaws.com"; $db_user = "devninja"; $db_pass = "Justtest\$_"; #using slash before special character $db_name = "db_devninja";
hope this helps