Reputation: 285
I am trying to connect to my data base and i get an error when I use 127.0.0.1 instead of localhost.
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.
If I use localhost instead of 127.0.0.1 it works fine. Anyone have any insight into this?
the code used to connect is
<?php
$db = new mysqli('127.0.0.1', 'root', '', 'dbname');
?>
Upvotes: 2
Views: 6956
Reputation: 660
Check the sql configurations. I'm going to list a few that should be checked that could cause this option. I do recommend sharing what version of php and sql you are using. Are you using LAMP? It is the same problem listed in the above comments. Newer versions of LAMP have changed the default to 127.0.0.1 for localhost. This is why it comes across as a different problem and you do need a different approach to fix it.
1) if my.cnf has a line reading skip-networking comment it out.
2) check the ect/hosts.allow file make sure there is a line that says
mysqld: ALL
3) check the ect/hosts.deny file and make sure there is only 1 line stating
ALL:ALL
Let us know if that fixed the problem.
Upvotes: 0