我使用 codeigniter my_model 类来更新我的表数据。
实际我需要查询的是
`UPDATE `pay_project` SET `awarded` = '129' WHERE `pay_id` = 1 and `status` ='y'
为此我尝试了 codeignter my_model 函数更新
$this->pay_project_model->update_by(array('pay_id'=>1,'status'=>'y'),$updateJob);
但是代码不工作,如果当时我尝试使用 update() 而不是 update_by() ,它会像这样显示
`UPDATE `pay_project` SET `awarded` = '129' WHERE 'id'=array()
请帮我解决这个问题?我也在尝试使用 update_many(),同样不起作用..
使用的模型是 https://github.com/jamierumbelow/codeigniter-base-model
最佳答案
试试这个 Active Records,它会让你知道你在做什么以及查询
function update($data = array(), $where = '') {
$where = array('pay_id'=>1,'status'=>'y');
$data = array('awarded' => '129');
$this->db->where($where);
$res = $this->db->update($this->main_table, $data);
$rs = $this->db->affected_rows();
return $rs;
}
关于php - 如何使用 Codeigniter mymodel 类在多个 where 条件下进行更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31284275/