0

I want my PHP script to hide any errors generated by a mysqli object but show any other ones. Is there a way to do this in PHP?

wecsam
  • 2,651
  • 4
  • 25
  • 46
  • http://php.net/manual/en/language.operators.errorcontrol.php Note that for best practice, the use of `@` is _not_ recommended, for the reasons noted in the red box on the doc page. – Michael Berkowski Feb 19 '12 at 01:41
  • possible duplicate of [How to hide an error message](http://stackoverflow.com/questions/2471471/how-to-hide-an-error-message) – Michael Berkowski Feb 19 '12 at 01:43
  • I don't want to go through my code and put an `@` in front of every statement that involves `mysqli`. I want to know whether there is an easier way before I write my own error handler function. – wecsam Feb 19 '12 at 01:45

1 Answers1

0

Creating a custom exception handler can make it quite simple. We can simply create a special class with functions that can be called when an exception occurs in PHP. The class must be an extension of the exception class. We can suppress errors of specific type here.

or simply you can use @ with error throwing functions in mysqli like @mysqli_errno() to suppress error messages

Try the instanceof operator, the is_a function or the get_class function to get error type:

$var instanceof MySQLi
is_a($var, 'mysqli')
is_object($var) && get_class($var) == 'mysqli'
  • If I used a custom exception handler, through `set_error_handler()`, I presume, how would I determine whether the error was generated by `mysqli`? – wecsam Feb 19 '12 at 01:47
  • 1
    Sorry, where does the `$var` variable come from? – wecsam Feb 19 '12 at 02:52