Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

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

like image 207
Ralph Riener Deleña Avatar asked Dec 06 '25 08:12

Ralph Riener Deleña


1 Answers

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.

like image 135
Daniel W. Avatar answered Dec 08 '25 20:12

Daniel W.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!