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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…