作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已将onError方法添加到AppModel,如下所示:
class AppModel extends Model {
function onError() {
$db = $this->getDataSource();
$err = $db->lastError();
$this->log("AppModel.onError: $err");
}
}
function admin_create() {
$this->Match->query('SELECT bang FROM');
}
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]
最佳答案
我不相信在使用模型的query()方法时会执行onError回调-如果存在SQL错误,则仅引发异常。
编辑:
抱歉,我应该提供一个示例来说明如何处理该错误:
try {
$this->Match->query('SELECT bang FROM');
} catch (Exception $e) {
/**
* Catch the exception - do your error handling here
*/
}
关于php - CakePHP : onError method in AppModel is not called when there is a sql error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8256734/
我是一名优秀的程序员,十分优秀!