avoid error log with mysql connection

1

Galera I make a connection to mysql using php. I do this:

mysqli_connect($ip_bd_mysql, $login_bd_mysql, $senha_bd_mysql, $banco);

The problem is that it's time for the BANK name to be wrong, and the system returns an error. How do I hide this error and customize it. to inform you that you hear an error with the connection data.

    
asked by anonymous 19.10.2016 / 13:18

2 answers

2

You can use a trycatch for any exception that occurs in an area where you can customize the response:

try {
    mysqli_connect($ip_bd_mysql, $login_bd_mysql, $senha_bd_mysql, $banco);
} catch (Exception $e) {
    return "Minha mensagem...";
}

You can still force errors, and it will fall into this same catch , for example:

try {
    if($ip_bd_mysql == '127.0.0.1')
          throw new Exception("Minha mensagem de erro customizada");
    mysqli_connect($ip_bd_mysql, $login_bd_mysql, $senha_bd_mysql, $banco);
} catch (Exception $e) {
    return $e->getMessage();
}

In the $e variable, you still have methods to have relevant error information, such as the original error message, file and line that occurred the error among others ...

To see exactly just give var_dump(get_class_methods($e)); .

To disable warning and notice try to put the following excerpt before execution:

error_reporting(0);
    
19.10.2016 / 13:25
1

Good morning!

If you only want to ignore the error for this function, try using @ together:

@mysqli_connect($ip_bd_mysql, $login_bd_mysql, $senha_bd_mysql, $banco);

Abs

    
19.10.2016 / 14:07