James Allan James Allan - 1 year ago 111
SQL Question

Mysql server not connecting anymore with servername

I was connected with my server using my server name.

ini_set('default_charset', 'UTF-8');

$servername = "my server name here";
$username = "xxxxx";
$pass = "xxxx";
$dbname = "xxxx";

$conn = mysqli_connect ($servername, $username, $pass, $dbname);
if(!$conn) {
die("Connection faild: ".mysqli_connect_error());

$conn->query("SET NAMES utf8");


All my aplications was working and now stopped.
Now is only connecting if i use my server ip.

There are the errors
**Warning: mysqli_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed

Connection faild: php_network_getaddresses: getaddrinfo failed


When i connect on the database with my login and pssword in my host provider
it enters fine,nothing changed.

Btw im using xampp.

Anyone knows why this is happening?

Answer Source

Normally, using xampp in Windows, we will set server name be "localhost"

$servername = "localhost";

If you want other name, please set in hosts file:

C:\Windows\System32\drivers\etc\hosts my_domain_name.com

And add "my_domain_name.com" (for example) into $servername variable

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download