phpcodeigniteractiverecordincrementquoting

How to turn off set() method's automatic identifier escaping in CodeIgniter's active record


I'm trying to use the code bellow to update the page count. I'd rather do with one one query, than running one to get the existing count first. Is there a way to tell CodeIgniter not to escape the query?

At the moment it's putting single quotes around my column incrementation statement 'page_views + 1' which is breaking the query.

 $this->db->where('id', $charity);
 $this->db->update('charities', array('page_views' => 'page_views + 1'));

Solution

  • set the values like this, it allows disabling escaping

    $this->db->set('page_views', 'page_views + 1', false);
    $this->db->where('id', $charity);
    $this->db->update('charities');