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);