P粉1619397522023-09-06 12:49:44
You can do this by disabling mysqli error reporting, but this shouldn't be done for any regular project. In fact, it looks like you're going about this problem the wrong way! You shouldn't want to disable error reporting, you should fix errors!
As you mentioned, if the error comes from an incorrectly constructed dynamic SQL statement, then your code should not contain any logic to handle this possible scenario because you don't want the error to be part of the design. Just like any other error, this is a bug in the PHP code. The fact that it manifests itself as a MySQL error is irrelevant. You must fix the code that builds the invalid SQL statement! Silencing errors does not help fix errors!
Assuming that your PHP code builds SQL from the constant SQL part (if it uses variables, then there will be bigger problems in your code), then your task is to determine which code path is causing the SQL keyword to be incorrect combination. You can partially infer this from the SQL errors. The exception message will tell you what the syntax error is. If the MySQL error is not related to broken syntax, the process is still similar: find the cause of the error and fix it.
Don't write special error handling logic around SQL code. It's confusing and absolutely unnecessary.