Hi Reader's,
Welcome to FindNerd, today we are going to discuss on display error messages from mysql response in Cakephp 2.5.6 .
Sometime you need show sql error messages to users when you get duplicate entries from database. Suppose you are developing a web application in cakephp then, if any duplicate entries exist in database then it will show following message to the user.
"Database Error : SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry"
It is not good way to show duplicity error from database. If you want to show proper message then you have to show proper error display message and set a view page. So to show error message on view page you have to pass information from the controller.
So after set view page you can display a proper message to users which you want to set on view page.
You can see following code :
<?php $this->set('errormsg', $e->getMessage()); ?>
If you want to use AJAX then, you can set it like this:
<?php $this->set('_serialize', array('errormsg')); ?>
I hope this blog will help you to set display error message from mysql response.
0 Comment(s)