当我运行这样的查询时:
$this->User->query("DELETE FROM users WHERE deleted = 1 AND created <= '".$created."'");
我怎么知道运行查询时是否有错误?
如果出现类似错误,我想向用户发送消息:
if(!$this->User->query("DELETE FROM users WHERE deleted = 1 AND created <= '".$created."'"))
$this->Session->setFlash('There was an error running this query');
此方法始终返回0,但查询正在运行且没有错误
答案 0 :(得分:2)
您想知道是否有错误,或者是否删除了任何记录?
您可以使用类似$this->User->deleteAll的内容
$this->User->deleteAll(array(
'deleted' => 1
'created <=' => $created
));
成功时返回布尔值True,失败时返回false。