Skip to content
Advertisement

How can I solve the uncaught PDOException “SQLSTATE[HY000] [1045] Access denied for user…”?

I’m using a free hosting solution for my MySQL database. However, when I try to connect to it through my PHP code it throws me a uncaught PDOException error and my access is denied. I can’t seem to find why the connection is denied as my credentials are correct.

I’m using Ionic 2 framework, if that helps.

Error:

PHP connection code:

Advertisement

Answer

The best way to catch the exception is to put your code in a try-catch block. But in your case I think you are putting the password in incorrect. The code which causes error (exception) should be in try block and then catch it like so:

You can read more about exception handling here.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement