如何使用Codeigniter my_model类为udate多个condetion?

7 php mysql codeigniter my-model-jami

我使用codeigniter my_model类来更新我的表数据.

Actulay我需要的查询是

`UPDATE `pay_project` SET `awarded` = '129' WHERE `pay_id` = 1 and `status` ='y'
Run Code Online (Sandbox Code Playgroud)

为此,我尝试了codeignter my_model函数更新

$this->pay_project_model->update_by(array('pay_id'=>1,'status'=>'y'),$updateJob);
Run Code Online (Sandbox Code Playgroud)

但是代码不起作用,如果我正在尝试update()而不是update_by(),那么它就像这样显示

`UPDATE `pay_project` SET `awarded` = '129' WHERE 'id'=array()
Run Code Online (Sandbox Code Playgroud)

请帮帮我解决这个问题?我也尝试使用update_many(),同样不起作用..

使用的模型是 https://github.com/jamierumbelow/codeigniter-base-model

Sya*_* KK 0

如果您使用 Codeigniter My_model 类,那么您需要像这样更改模型才能使用 update_by() 函数

class Pay_project_model extends MY_Model {
protected $table='pay_project';
function update_by($where = array(),$data=array())
 {
        $this->db->where($where);
        $query = $this->db->update($this->table,$data);
        return $query;
  }
}
Run Code Online (Sandbox Code Playgroud)

在 My_model 类中,没有默认选项通过多个 where 条件更新类,因此您需要编写 update_by() 函数。简单地将函数复制粘贴到您的类中,这将完美地工作。