function updateVisitsStatus($today){
/*
*
$this->db->select('exp_datetime, status_id');
$this->db->from('visits');
$this->db->where('exp_datetime <', $today);
$this->db->where('status_id', 0);
echo "<pre>"; print_r($this->db->get()->result());exit;
*
*/
$this->db->where('exp_datetime <', $today);
$this->db->where('status_id', 0);
$this->db->update('visits', 'status_id = -4 ');
}
带注释的查询根据给定条件打印两条记录。因此,查询应该使用字段 status_id
中的新值更新两条记录,但实际上没有。
在这个过程中我错过了什么?
最佳答案
您必须将值作为数组或对象传递给函数update
。尝试一下,
// define array of values
$data = array(
'status_id' => -4
);
$this->db->where('exp_datetime <', $today);
$this->db->where('status_id', 0);
$this->db->update('visits',$data);
关于php - 我无法在 codeigniter 中运行更新查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26230075/