I have added the onError method to AppModel as follows:
class AppModel extends Model {
function onError() {
$db = $this->getDataSource();
$err = $db->lastError();
$this->log("AppModel.onError: $err");
}
}
Inside my matches controller I have:
function admin_create() {
$this->Match->query('SELECT bang FROM');
}
When I visit /admin/controllers/create it get the following error in the log file but nothing from the code in the onError method.
2011-11-24 20:50:43 Warning: Warning (512): SQL Error: 1064: 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
1 in
[/home/larry/workspace/cbhk/cake/libs/model/datasources/dbo_source.php,
line 684]
Also, when I set a breakpoint in admin_create it is reached but the breakpoints in onError cannot be reached. Any idea as ideas?
I don’t believe the onError callback is executed when using the Model’s query() method – only an exception is thrown if there is a SQL error.
EDIT:
Sorry, I should have provided an example of how you could handle the error: