Error in connection with bank using PDO

1

Error message:

  

Error: SQLSTATE [HY000] [2002] php_network_getaddresses: getaddrinfo   failed: This host is not known.

code

    $db_name = 'db_name';
    $hostname = 'mysql.hostinger.com.br';
    $username = 'username';
    $password = 'password';

    $sql = "INSERT INTO atividade(titulo, descricao, data_atividade) VALUES(:titulo, :descricao, :data_atividade);";

    try {
        $dbh = new PDO('mysql:host=$hostname;dbname=$db_name', $username, $password);
    } catch (PDOException $e) {
        echo 'Error: ' . $e->getMessage();
    }'

I just left the $hostname filled correctly because it is in it that is giving the error. If anyone can help me, thank you in advance!

    
asked by anonymous 23.09.2016 / 02:15

2 answers

3

This domain name is basically not accessible on the public network. If the code is hosted on hostinger, just put it as localhost. Another alternative is to enter the ip address of the mysql server (which is the same ip as the hosting).

    
23.09.2016 / 03:01
1

In fact the hostname is incorrect, to access via external php (outside the localhost of hostinger) or any other language, you should use 'sql141.main-hosting.eu'

$db_host = "sql141.main-hosting.eu";
$db_user = "u265779999_meme";
$db_pass = "admin";
$db_name = "u265779999_teste";
$conexao = mysqli_connect("$db_host", "$db_user", "$db_pass", "$db_name");

if(mysqli_connect_errno($conexao)){
    $resultado = mysqli_connect_error();
    exit;
}
    
08.06.2018 / 20:54