How to connect project to hostinger

0

I'm wondering how to connect the project to the hostinger.

I have the following code:

    $servidor = "mysql.hostinger.com";
    $usuario = "u*_agnd";
    $senha = "";
    $dbname = "u*_agnd";

    //Criar a conexao
    $conn = mysqli_connect($servidor, $usuario, $senha, $dbname);

It returns me these messages:

mysqli_connect(): php_network_getaddresses: getaddrinfo failed: Este host n�o � conhecido. in

mysqli_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Este host n�o � conhecido. in

mysqli_query() expects parameter 1 to be mysqli, boolean given in
    
asked by anonymous 03.09.2018 / 15:05

1 answer

0

The safest way to do this is by using PDO. but mysqli also serves. Mysqli:

<?php

ini_set('default_charset','UTF-8'); //Definindo UTF-8 PARA IR AO PT-BR
$servername = "nome_do_servidor"; //NOME DO SERVIDOR
$database = "nome_do_banco"; //NOME DO BANCO
$username = "usuario"; //NOME DO USUARIO
$password = "senha"; //SENHA DO USUARIO


//CONEXÃO AO BANCO
$conn = mysqli_connect($servername, $username, $password, $database);
$conn->query("
SET NAMES utf8"); //TODOS SUAS QUERYS(DADOS) VÃO VIR COM UTF-8 JÁ

// VERIFICANDO A CONEXÃO
if (!$conn) {
      die("Connection failed: " . mysqli_connect_error());
}

echo "";
?>

In PDO it would look like this (object oriented):

   try{
    $conexao = new PDO //conexao ('tipo_do_banco:,host=nome_do_servidor;dbname=nome_do_banco','usuario','senha';
    $conexao->SetAttribute(PDO::ATTR_ERRMOD, PDO::ERRMODE_EXCEPTION);
}catch(PDOException $error){
    echo("O erro foi:") . $error getMessage();
}
    
03.09.2018 / 15:10