1

I have a general exception handler for my PHP code, but want to extend that to handle mysqli exceptions that are now being generated due to my use of prepare/bind/execute statements. I have spent hours looking for coding examples of this, but I can't find any. I am not looking for try/catch examples. Any help would be greatly appreciated.

5
  • 1
    @Geoff A general exception handler should handle mysqli exceptions as well. So you don't have to extend it. Why do you think it's needed? Basically, mysqli exceptions are no different, and handled the same way as others. Commented Sep 2, 2022 at 17:55
  • I can see that my general exception handler was receiving mysqli exceptions. I thought that the mysqli_sql_exception class would provide more information. Commented Sep 2, 2022 at 21:08
  • What kind of more information? Can you provide some context? Commented Sep 3, 2022 at 5:01
  • I have noted that the line number doesn't always line up with the actual code, and the error message can be something cryptic like: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 40" I would like to get the entire SQL string that caused the error. Commented Sep 3, 2022 at 11:46
  • to use near '' means at the very end. I don't see why would you need the entire query as you can see the query right in the code, aren't you? As long as you are using prepared statements, there would be no syntax errors at all, so there is no point in seeing the SQL. but if you need it, you will have to write wrappers for prepare that catches the exception, adds SQL, and throws the new exception. Commented Sep 3, 2022 at 14:58

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.