php 警告:mysqli_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No such host is known

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18161731/
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 17:04:48  来源:igfitidea点击:

Warning: mysqli_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No such host is known

phpmysqlwampwampserver

提问by Stelios Voskos

I have just downloaded the wamp server. I want to establish a connection to MySQL database with PHP and I'm using the root user, localhost and the name of my database. My code seems to be correct but when I run it on wamp, I get the following error: Warning: mysqli_connect(): php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\wamp\www\cone.php on line 8 and Warning: mysqli_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No such host is known.

我刚刚下载了 wamp 服务器。我想用 PHP 建立到 MySQL 数据库的连接,我使用的是 root 用户、localhost 和我的数据库的名称。我的代码似乎是正确的,但是当我在 wamp 上运行它时,出现以下错误:警告:mysqli_connect():php_network_getaddresses:getaddrinfo 失败:没有已知这样的主机。在 C:\wamp\www\cone.php 第 8 行和警告:mysqli_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No such host is known。

Also, the error message that I haven't been connected to the database(from my if statement) is displayed.

此外,还显示了我尚未连接到数据库(来自我的 if 语句)的错误消息。

Does this mean that I have to do some extra configuration on the server?

这是否意味着我必须在服务器上做一些额外的配置?

Here is my code:

这是我的代码:

<?php

<?php

$dbcon = mysqli_connect('root','', 'localhost', 'people');

$dbcon = mysqli_connect('root','', 'localhost', 'people');

`if(!$dbcon)` 
`{`
    `die('error connecting to database');`
`}`
`echo "success";`

?>

?>

Thank you in advance

先感谢您

回答by Raymond Nijland

mysqli_connect('root','', 'localhost', 'people');

You are passing root in as hostname.

您将 root 作为主机名传入。

try this

尝试这个

mysqli_connect('localhost','root', '', 'people');

this will connect to localhost with username root passwoord "" and default database people.

这将使用用户名 root 密码 "" 和默认数据库人员连接到本地主机。

maybe better to change localhost with 127.0.0.1

用 127.0.0.1 更改 localhost 可能更好