How to send error ans MySQL query from pdo_error.ctp file?

Hello,
That a long time, I have code in CakePHP. I created a great CakePHP application and missed some step.

It a shop. A order is done and the data are sent via a form. Some fields of the form are empty and the problem the table where are going to be same has the field content set Not NULL.

The the following error is displayed:

Error: SQLSTATE[23000]: Integrity constraint violation: 1048 Column ‘content’ cannot be null

SQL Query: INSERT INTO cakephp.basketsitems (name, qt, basket_id, article_id, price, noarticle, content, attribut, catpage, image) VALUES (‘Aiguilles d'acuponcture Premium’, 1, 719, 20251, 8, ‘T5057’, NULL, ‘0,25 x 25 mm’, ‘314’, ‘T5057_1.jpg’)

Notice: If you want to customize this error message, create app/View/Errors/pdo_error.ctp

Then I created the file pdo_error.ctp and I customized a message.

The problem, the customer can not report us the error because he will not uderstand the SQL message.

My is, how can modified the pdo_error.tpl file to send me an e-mail with the error message and SQL query?
Or how can I create a log file with this message? But it would be great if I could be inform, as well.

Many thank for your help!!

Hi!
What version of cake do you use?
In older versions you could write a model callback by using onError() function from cake e.g.:
function onError()
{
// sql error
$error = $this->getDataSource()->error;

// email sql error
mail('webmaster@example.com', 'SQL errors', $error);
}

In newer version you could use ErrorHandler by implementing application specific exception handling or use your own custom renderer with ‘exceptionRenderer’.
Link: https://api.cakephp.org/3.6/class-Cake.Error.ErrorHandler.html

Regards