我想这样查询sql:
update table set `status` = 2 where id=1 and `status`=1
以及从何处获取受影响的行。我发现
doc
,
但是如何更新
status
并在sql中使用where?
我的cakephp版本是2.4.6。
更新已解决的:
现在我最后做的这个函数是:
public function updateById($id,$data,$status = ''){
if( empty($id) ) {
return false;
}
$conditions = array();
$conditions['id'] = $id;
if($status != ''){
$conditions['status'] = $status;
}
$this->updateAll($data, $conditions);
return $this->getAffectedRows();
我在控制器中调用如下函数:
$this->MyModel->updateById(5, array('views'=>100,'status'=>2), 1);
可以确保记录从
地位
1至2