Try some basic troubleshooting like https://stackoverflow.com/questions/58045855/pdoexception-sqlstatehy000-2002-connection-refused
And is the mysql pdo driver un-commented.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi😊 I am almost new here on Laracasts and thank you for the membership. I got a huge problem I can't find out about. But my PDO connection won't work after I wanted it to print out an error message if it fails to connect with the error code.
I got a problem with my new PDO connection. I wanted to change it because I want it to print to screen the error code and an error message if there is no contact with MySQL DB, and give a message if it's connected. But what has happened is like nothing. Or, the connection script won't connect. It writes out the message on the screen.
I have used some hours trying to fix the problem but without luck. So, I ask you "gurus" to be so kind and look over it for me and fix the problem for me? I can't manage to fix it myself. Please😊
By the way. This is the error message i am receiving: Unable to connect to the database server: SQLSTATE[HY000] [2002] Connection refused
I have checked my user data like password, username, address to the host and DB name several times, and over and over again. So there is something in the script itself, but I can't find out what or where.
Please or to participate in this conversation.