Reputation: 53
When I try to connect to host on mac using MAMP I get this error
php_network_getaddresses: getaddrinfo failed: nodename nor servname
provided, or not knownfailed
This is my php code.
$con=mysqli_connect("127.0.0.1”,”pks”,”sonisoni123”,”GDRS");
Echo mysqli_connect_error();
if($con)
{
echo "success";
}
else
{
echo "failed";
}
?>
I don't know where I am going wrong any help would be appreciated.
Upvotes: 5
Views: 26755
Reputation: 4374
One more reason why you are getting this error is you might have commented below line to your hosts file or you don't have this line.
127.0.0.1 localhost
if you are using Mac go to /etc/hosts
and add or uncomment 127.0.0.1 localhost
line.
This might fix your problem
Upvotes: 1
Reputation: 46
You might wanna switch your quote types around the connection variable; they aren't the exact same (even though they are similar), which could cause PHP to read the strings differently.
Try this:
$con=mysqli_connect("127.0.0.1","pks","sonisoni123","GDRS");
Echo mysqli_connect_error();
if($con)
{
echo "success";
}
else
{
echo "failed";
}
?>
Upvotes: 3