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

巧了我就是萌 提交于 2019-12-11 19:18:58

问题


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.

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?

Here is my code:

<?php

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

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

?>

Thank you in advance


回答1:


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

You are passing root in as hostname.

try this

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

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

maybe better to change localhost with 127.0.0.1



来源:https://stackoverflow.com/questions/18161731/warning-mysqli-connect-hy000-2002-php-network-getaddresses-getaddrinfo-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!