警告:mysqli_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No such host is known [英] Warning: mysqli_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No such host is known

查看:123
本文介绍了警告: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.

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.

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

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

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

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

这是我的代码:

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

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

?>

提前致谢

推荐答案

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

您将 root 作为主机名传入.

You are passing root in as hostname.

试试这个

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

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

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

最好用 127.0.0.1 更改 localhost

maybe better to change localhost with 127.0.0.1

这篇关于警告:mysqli_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No such host is known的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆