0
votes

When I connect from localhost I get this error

Warning: mysqli::mysqli(): (HY000/2002): 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 C:\xampp\htdocs\vici\index.php on line 9 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.

here is my code

$servername = "27.111.132.11";
$username = "root";
$password = "123";
$dbname = "test";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
1
can you ping that IP? - delboy1978uk
Are you sure you're trying to connect to the correct IP? - user4524061
sometimes it happens to me too.. I just restart both apache and mysql and the magic happens - yanntinoco
@ Brent Lobbezoo yes correct ip - Juboraj S Islam
@ delboy1978uk yes i can ping - Juboraj S Islam

1 Answers

0
votes

MySQL connection driver does not get any meaningful server at the location of localhost. So use,

'hostname' => '127.0.0.1'

rather than

'hostname' => 'localhost'