CodeIgniter Forums

Full Version: db->set() escaping array with flag on
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]xatrix[/eluser]
Code:
$this->db->set(array('upvotes' => 'upvotes - 1', 'downvotes' => 'downvotes + 1'), FALSE);
$this->db->where('id', $answer_id);
$this->db->update('answers');

Even though escape has been set to FALSE, 'upvotes - 1' and 'downvotes - 1' are still escaped.

Now if I break each set on it's own line as

Code:
$this->db->set('upvotes', 'upvotes - 1', FALSE);
$this->db->set('downvotes', 'downvotes + 1', FALSE);

It works. Can someone confirm this?

-edit-

Please delete this. I had to set the second parameter (value) to NULL when using an array.

El Forum

[eluser]crispyhihats[/eluser]
im glad this wasn't deleted...seems this was the only post I could find on this.


When using $this->db->set() with an array of data and you need to do something like db_column = db_column + 1, you must set the second parameter as NULL... so it would look like this

$this->db->set($arrayData, NULL, FALSE);