2

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

1 Answers1

14

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.

Daniel W.
  • 31,164
  • 13
  • 93
  • 151
  • 1
    Minor clarification in case it isn't clear to the reader - FTP is the means by which the server has files sent to it, but this is not the reason why the database server is not visible outside of the host. – halfer Feb 24 '16 at 18:40
  • @halfer I have changed my answer accordingly, hope it makes things even clearer. – Daniel W. Feb 24 '16 at 20:54
  • 1
    That's great, thanks Dan! Upvoted already. (Aside: I am hoping that the database server is firewalled from the internet, and they are not just using the lack of public DNS as a security feature. Otherwise people would be able to edit their own hosts files and connect to the database server from outside the host's LAN...) – halfer Feb 24 '16 at 20:55
  • 1
    @halfer I googled "hostinger.ph" and I think they are big enough to isolate their networks and machines well enough. But of course you are right, A public IP address is even fancier than a hostname ;-) – Daniel W. Feb 24 '16 at 21:00
  • Hi i edited my post, as well as the error message that i have so far – Ralph Riener Deleña Feb 25 '16 at 03:45