Monday, January 30, 2023
Google search engine
HomeDevOpsUnable to connect to AWS RDS through PDO

Unable to connect to AWS RDS through PDO

This is a very old question about Unable to connect to AWS RDS through PDO, but I had the exact same issue and wanted to document it here for anyone who finds this later.

The Problem

  1. You can connect to your database (Amazon RDS) manually from the command line.
  2. You can connect to your database via mysqli in PHP.
  3. You can not connect to your database via PDO in PHP.

Amazon RDS is a managed database service. It’s responsible for most management tasks. By eliminating tedious manual tasks, Amazon RDS frees you to focus on your application and your users. We recommend Amazon RDS over Amazon EC2 as your default choice for most database deployments.

In the following table, you can find a comparison of the management models in Amazon EC2 and Amazon RDS.

The Solution

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.

example:

$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 article Unable to connect to AWS RDS will help you 🙂

YOU CAN SUPPORT DEVNINJA WITH A CUP OF COFFEE

As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online. to search or browse the published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or more ) as a token of appreciation.

Support Us

DevNinja
DevNinja
System & Network Administrator Ninja
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

16 + 5 =

- Advertisment -
Google search engine

Most Popular

Recent Comments