php 警告:mysqli_connect():php_network_getaddresses:getaddrinfo 失败:名称或服务未知
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35607946/
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: Name or service not known
提问by Ralph Riener Dele?a
This is db.php IM USING CLOUD9 as my host
这是 db.php IM USING CLOUD9 作为我的主机
function getDB() {
$dbhost="paralphdigm-vtms-2622120";
$dbuser="paralphdigm";
$dbpass="";
$dbname="vtms_db";
$port = 3306;
$dbConnection = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
$dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $dbConnection;
}
}
I edited my code to this now*
我现在将代码编辑为此*
Heres the error message Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] Connection refused' in /home/ubuntu/workspace/db.php on line 8
继承人的错误消息致命错误:未捕获的异常 'PDOException' 与消息 'SQLSTATE[HY000] [2002] 连接被拒绝' in /home/ubuntu/workspace/db.php on line 8
回答by Daniel W.
php_network_getaddresses: getaddrinfo failed: Name or service not known
php_network_getaddresses:getaddrinfo 失败:名称或服务未知
In non-technicalwords, this error message means: "I don't know the address of the server."
用非技术术语来说,此错误消息的意思是:“我不知道服务器的地址。”
In technicalwords, it means the hostname you try to connect to has no public nameserver record.
用技术术语来说,这意味着您尝试连接的主机名没有公共名称服务器记录。
The database server is only accessable from within a few specific servers, as a security feature, to prevent the whole world from accessing it. So not everyone can try to hack or overload (DoS) it!
数据库服务器只能从几个特定的服务器中访问,作为一项安全功能,以防止整个世界访问它。所以不是每个人都可以尝试破解或重载(DoS)它!
A host that is allowed to connect to the database server might most probably be the server you upload your html/php/.. files to.
允许连接到数据库服务器的主机很可能是您将 html/php/.. 文件上传到的服务器。
Although you are mixing PDO, MySQLi and mysql, which is bad, the error is caused by network related stuff, not by programing mistakes.
虽然你混合了 PDO、MySQLi 和 mysql,这是不好的,但错误是由网络相关的东西引起的,而不是由编程错误引起的。
The question changed completely after your edit.
在您编辑后,问题完全改变了。
"Connection refused" means your host knows the address and can reach the database server, but it is not allowed to connect. It refers to the same situation as before, your host is "in a different neighborhood" now which still is not "friendly" to the db.
“连接被拒绝”表示您的主机知道地址并且可以访问数据库服务器,但不允许连接。它指的是与以前相同的情况,您的主机现在“在不同的社区”,这对数据库仍然不“友好”。