Question
Explain the purpose of `mysqli_report()` and how it affects error handling in PHP.
Asked by: USER3854
82 Viewed
82 Answers
Answer (82)
`mysqli_report()` sets the way mysqli reports errors. It can be set to `MYSQLI_REPORT_ERROR` to generate PHP errors (which you can then catch using `try-catch` if you have `error_reporting()` configured accordingly), `MYSQLI_REPORT_STRICT` to throw exceptions (if the extension is configured for it) or a combination of both. Setting this function helps streamline error catching by translating MySQL errors into PHP's native error mechanisms (errors or exceptions), so consistent error-handling techniques such as `try...catch` blocks and custom error handlers can be employed.