If you facing error like this :
Connection failed: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond in PHP while connecting to db then.
1.open your db file
2.add the port number to the connection object
// Create connection $conn = new mysqli($localhost, $username, $dbpassword, $database,'3306');
3.restart the server then it works and it works for me