gpt4 book ai didi

php - CakePHP : onError method in AppModel is not called when there is a sql error

转载 作者:行者123 更新时间:2023-12-03 07:55:29 24 4
gpt4 key购买 nike

我已将onError方法添加到AppModel,如下所示:

class AppModel extends Model {
function onError() {
$db = $this->getDataSource();
$err = $db->lastError();
$this->log("AppModel.onError: $err");
}
}

在我的比赛 Controller 中,我有:
function admin_create() {
$this->Match->query('SELECT bang FROM');
}

当我访问/admin/controllers/create时,它在日志文件中得到以下错误,但onError方法中的代码未得到任何错误。

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]



另外,当我在admin_create中设置一个断点时,可以到达,但无法在onError中断点。有想法吗?

最佳答案

我不相信在使用模型的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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com