PHP error when connecting to Mysql database

Asked

Viewed 521 times

0

Although I haven’t changed at all the settings of my Mysql database that has been working well for months, the connection has stopped working.

This is the PHP command I use to make the connection:

$this->link = @mysqli_connect($this->host,$this->user,$this->pass) or die("Sem conexão ". mysqli_connect_error());

Mysqli_connect_error returns this error message:

php_network_getaddresses: getaddrinfo failed: The requested name is valid, but no data of the requested type was found.

These are the UOL Host connection settings:

public $host = "djbteste.mysql.uhserver.com";
public $user = "********";
public $pass = "********";
public $db = "djbteste";

But it’s an intermittent mistake, it happens a few times throughout the day and only for a few minutes. I contacted the support (which is terrible!) of UOL Host, and they said that everything is fine with the database...

  • 1

    There may be some problem in the infrastructure that causes a package loss at peak times, one way around it would be for you to remove the die() and place the connection line within a while, to try a second or third time (but not too long) before interrupting execution.

  • thanks @Giovanninunes found interesting your suggestion and I will make this test.

1 answer

0


Try using the server IP in your variable $host.

public $host = "127.0.0.1.00"; // IP do servidor
public $user = "********";
public $pass = "********";
public $db = "djbteste";

Another thing, enter the name of the bank as well, like this:

$this->link = @mysqli_connect($this->host,$this->user,$this->pass, $this->db);

or so:

$this->link = @mysqli_connect($this->host,$this->user,$this->pass);
mysqli_select_db($this->link,$this->db);
  • 1

    Andrei Coelho, I made the changes you suggested and will observe for some time the performance of the database. If you solve the problem I will mark your answer as correct. Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.