Unable to connect to MySQL DB through PHP

My PHP code to connect with mysql was working till yesterday. Today its showing exception “Uncaught PDOException: SQLSTATE[HY000] [2002] Connection refused”.
I am able to log in to PhpMyAdmin using same credentials. But not able to connect through PHP.

This is the code I used

$serverName = 'localhost';
$dbName = 'dbname';
$user = "username";
$password = 'password';
$conn = new PDO("mysql:host=$serverName;dbname=$dbName", $user, $password);
1 Like

i had the same problem, i created new Db and try to connect it with the same script but it show again error Connection refused…i spent hours today but problem is not solved till now…

1 Like