Reputation:
im working on a website which mostly uses the database. the problem is that im geting the following error: mysqli_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known
I cant figure out how to fix it. I've penta-checked the connect and it seems to be okay.
function connect($hostname, $username, $password, $database)
{
$conid = mysqli_connect($hostname, $username, $password, TRUE);
if($conid == FALSE)
{
if(DEBUG == TRUE)
{
show_error("MySQL Connection using `$hostname`, `$username`, `$password` was refused");
}
return;
}
else
{
$dbid = mysqli_select_db($database, $conid);
if($dbid == FALSE)
{
if(DEBUG == TRUE)
{
show_error("MySQL could not connect to database `$database`");
}
return;
}
else
{
self::$connections[] = $conid;
self::$connection = $conid;
}
}
}
The code is writen in 2010 and then somehow it worked. Is it possible to fixit?
Upvotes: 7
Views: 38409
Reputation: 531
Just came across the error myself between 2 working PHP 7.1, Apache 2.4 & mariaDB 10.2/10.4 servers.
The issue for me was caused by using "http://1.2.3.4/" as the Database Host - this will cause PHP to return this error mysqli_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known
. For me this was of course some bogus error for me as they are both individually hosting the same websites & databases so there was no reason for it not to work.
The host variable should only be the IP address "1.2.3.4" or domain/subdomain (excluding the protocol) "example.com" or "subdomain.example.com" - which now connects correctly.
Upvotes: 0
Reputation: 323
I had a similar issue, My Issue was resolved by checking and resolving DNS resolution (in our case, the use in cagefs had different /etc/hosts than the core system)
Upvotes: 0
Reputation: 3006
It's the server hosting issue. You'd have to check with the hosting.
You can also read more tips at this link: http://albertech.net/2011/05/fix-php_network_getaddresses-getaddrinfo-failed-name-or-service-not-known/
Upvotes: 2