Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

php - Warning: mysqli_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known

This is db.php IM USING CLOUD9 as my host

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

php_network_getaddresses: getaddrinfo failed: Name or service not known

In non-technical words, this error message means: "I don't know the address of the server."

In technical words, 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!

A host that is allowed to connect to the database server might most probably be the server you upload your html/php/.. files to.

Although you are mixing PDO, MySQLi and mysql, which is bad, the error is caused by network related stuff, not by programing mistakes.


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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...