PHP error connecting database to server

Asked

Viewed 268 times

0

I’m having a doubt when I change my credentials of the database at localhost for the credentials of the database at sql server give me this php error

    Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: Este anfitrião não é conhecido. in C:\xampp\htdocs\Contactos_BD\conexao.php on line 6

    Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Este anfitrião não é conhecido. in C:\xampp\htdocs\Contactos_BD\conexao.php on line 6 

Code:

$host="*host*";
$usuario="*user**";
$senha="*pass**";
$bd="*bd**";
$mysqli= new mysqli($host,$usuario,$senha,$bd);
$mysqli=mysqli_connect($host,$usuario,$senha,$bd);
if ($mysqli->connect_error) {
    die('Connect Error (' . $mysqli->connect_errno . ') '
            . $mysqli->connect_error);
}
  • 1

    It seems to me that they are wrong. You can connect with them directly in the bank without PHP?

  • Yes, by localhost the problem is that when I enter the server credentials it does not give, sql management studio enters and I can run query’s without problem (with the same credentials as the server)

  • Could [Edit] ask the question and add how you are making the connection? Remember to change the user and password before posting here for security.

  • Is already up to date!

  • It’s a problem with Host.

  • So how can I fix?

  • 1

    Two possibilities: you’re trying to access an incorrect host, so we can’t help you, because we don’t know what it is. Another is: your database host has a firewall and only allows a certain range of Ips to access, and your php script is on another server with IP that is not of the allowed range.

Show 2 more comments

1 answer

2

Uses the function sqlsrv_connect() you can go to the Php website to learn more about this function

Browser other questions tagged

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