ZF-4580: Improving exception messages for failed database queries
When a query fails against a database adapter, it is most commonly during the query process which throws an exception with the database error message. It would be most useful to include the statement that failed to help with further debugging (especially when reading error messages from an error log).
For example, for the Mysqli adapter you would see: Fatal error: Uncaught exception 'Zend_Db_Statement_Mysqli_Exception' with message 'Mysqli prepare error: 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 .... in /home/www/production/library/Zend/Db/Statement/Mysqli.php:85
A small change to the exception throwing code could deliver a much more useful message:
Zend_Db_Statement_Mysqli line 85: throw new Zend_Db_Statement_Mysqli_Exception("Mysqli prepare error: " . $mysqli->error . '. Statement was: ' . (string) $sql); //Adding the sql statement to the error message