PDO - Showing bank information

Asked

Viewed 60 times

0

While trying to connect to Database without internet connection the program shows me this error message:

Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2002] Network is unreachable in /Library/WebServer/Documents/solucoes/includes/conexao.php:4 Stack trace: #0 /Library/WebServer/Documents/solucoes/includes/conexao.php(4): PDO->__construct('mysql:host=teste_sis', 'user123', 'senha123', Array) #1 /Library/WebServer/Documents/solucoes/includes/logar.php(7): con() #2 {main} thrown in /Library/WebServer/Documents/solucoes/includes/conexao.php on line 6

This same message shows me both the Host of the bank as user and password, I wonder if there is any way to hide this information or if there is any error in my connection code with the bank.

PDO connection code:

function con (){
    $user = "user123";
    $senha = "senha123";
    $pdo = new PDO("mysql:host=186.111.111.111;dbname=teste_sis", $user, $senha,array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));    
    return $pdo;
}

1 answer

0


Stick to the "Uncaught Pdoexception". Just capture the exception thrown in this case and treat it the way you want.

try {
    $pdo = new PDO(...);
} catch (PDOException $e) {
    die('Em manutenção!');
}

You can read more about documentation.

Browser other questions tagged

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