You can use a trycatch
for any exception that occurs it falls into 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 mistakes, 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 variable $e
, you still have methods to have relevant error information such as original error message, file and line that error occurred among others...
To see exactly just give one var_dump(get_class_methods($e));
.
To disable warning
and notice
try to put the following snippet before the execution:
error_reporting(0);
Do you display errors in production environment? an if in connection already solves.
– rray
in production environment no. But it keeps generating a log with the error.
– Hugo Borges