php mysqli_connect(): php_network_getaddresses: getaddrinfo 失败: 名称或服务未知

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22946763/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:23:32  来源:igfitidea点击:

mysqli_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known

phpmysqli

提问by Meletis Flevarakis

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 knownI cant figure out how to fix it. I've penta-checked the connect and it seems to be okay.

我在一个主要使用数据库的网站上工作。问题是我收到以下错误:mysqli_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known我不知道如何修复它。我已经对连接进行了五项检查,似乎没问题。

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?

该代码是在 2010 年编写的,然后以某种方式起作用了。有没有可能修好?

回答by Santosh Achari

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/

您还可以在此链接中阅读更多提示:http: //albertech.net/2011/05/fix-php_network_getaddresses-getaddrinfo-failed-name-or-service-not-known/

回答by user5167284

Your PHP server upgraded and your hosting didn't support it.

您的 PHP 服务器已升级,但您的主机不支持它。

回答by Jacob Evans

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)

我有一个类似的问题,我的问题是通过检查和解析 DNS 解析解决的(在我们的例子中,在 Cagefs 中使用的 /etc/hosts 与核心系统不同)

回答by Bim

Just came across the error myself between 2 working PHP 7.1, Apache 2.4 & mariaDB 10.2/10.4 servers.

刚刚在 2 个运行的 PHP 7.1、Apache 2.4 和 mariaDB 10.2/10.4 服务器之间遇到了错误。

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.

我的问题是使用“ http://1.2.3.4/”作为数据库主机引起的 - 这将导致 PHP 返回此错误mysqli_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known。对我来说,这对我来说当然是一些虚假错误,因为它们都单独托管相同的网站和数据库,因此没有理由不工作。

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.

主机变量应该只是 IP 地址“1.2.3.4”或域/子域(不包括协议)“example.com”或“subdomain.example.com” - 现在可以正确连接。