Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • 2
    For the most part, I agree, however 'Your Common Sense' i disagree with, "Not just write code to circumvent an error" what do you think a try...catch does, it circumvents the error to prevent the codebase exiting out in an uncontrolled manner, some errors you can't fix in code E.G DB server has gone away, you just have to manage the error and circumvent the error to poduce a valid result. Commented Sep 9, 2020 at 14:44
  • 4
    @Barkermn01 that's a proper concern of yours but you are drawing wrong conclusions from it. Of course your application should produce a valid result (which, in case of a "Mysql has gone away" error should be a generic 500 error page). But you have to understand that such a valid result is not a concern of your database code. Your database related code should work with a database. Whereas showing the error page should be a concern of a different code. See here: phpdelusions.net/articles/error_reporting Commented Sep 9, 2020 at 14:50
  • 1
    "Uncaught exception, in turn, makes a PHP fatal error" Is causing a fatal error a good idea on a PRODUCTION server (for mysql errors)? Aren't there a few situations where the error indicates a problem that your script should deal with, and continue however it can; e.g. inform the user that you can't give them that info right now, while alerting an operator to investigate? EDIT I see, where needed you try..catch mysql errors (that you have converted to php errors). Commented Jul 10, 2021 at 12:32
  • 1
    @ToolmakerSteve surely you meant the error handler, not a try catch Commented Jul 22, 2022 at 13:46
  • 1
    As of PHP 8.1.0, the default setting is MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT. Previously, it was MYSQLI_REPORT_OFF. php.net/manual/en/mysqli-driver.report-mode.php Commented Nov 18, 2022 at 17:29