php 警告:mysqli_connect():php_network_getaddresses:getaddrinfo 失败:不知道这样的主机。但我显然必须在那里主持
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31352189/
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
Warning: mysqli_connect(): php_network_getaddresses: getaddrinfo failed: No such host is known. Yet I clearly have to host there
提问by NotInternetExplorer
I have a site written in PHP that I'm creating. But I'm having this issue when I connect it to the database. When I load the page, I get the top:
我有一个我正在创建的用 PHP 编写的网站。但是当我将它连接到数据库时,我遇到了这个问题。当我加载页面时,我得到了顶部:
Warning: mysqli_connect(): php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\socialtest\inc\connect.inc.php on line 7
Warning: mysqli_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\socialtest\inc\connect.inc.php on line 7
This is connect.inc.php. The file which establishes the connect to the MySQL database:
这是connect.inc.php。建立与 MySQL 数据库的连接的文件:
$dbc = mysqli_connect('USER','PASSWORD','SERVER','DATABASE');
#OR die('Captian, we have failed' .
# mysqli_connect_error());
?>
The server name is 'localhost' and I never had a problem with it until recently.
服务器名称是“localhost”,直到最近我才遇到问题。
Please let me know how I can solve this issue as I've tried everything I can think of and I'm out of options.
请让我知道如何解决这个问题,因为我已经尝试了所有我能想到的方法,但我别无选择。
I'm using Apache2.2, PHP .5.6.9 and MySQL56 on Windows Vista.
我在 Windows Vista 上使用 Apache2.2、PHP .5.6.9 和 MySQL56。
Thanks!
谢谢!
回答by zilongqiu
As "mario" said, your mysqli_connect syntax is wrong.
正如“ mario”所说,您的 mysqli_connect 语法是错误的。
http://php.net/manual/fr/mysqli.construct.php
http://php.net/manual/fr/mysqli.construct.php
The right syntax is for example :
正确的语法是例如:
mysqli_connect('localhost', 'my_user', 'my_password', 'my_db');