CodeIgniter Forums
query builder class help - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: query builder class help (/showthread.php?tid=62427)



query builder class help - raoh - 07-13-2015

Hello everybody,

I have a little question about the query builder class.
Using normal sql I'd do this

PHP Code:
Update table set val val 3 where id 1

How can i do the same thing with the query class ? The code below doesn't work

PHP Code:
$this->db->set(array('val' => 'val+1'))->where(array('id' => 1))->update('table'); 
thank you for helping !


RE: query builder class help - pdthinh - 07-13-2015

Disable auto escape may work:

PHP Code:
$this->db->set(array('val' => 'val+1'), ''FALSE)->where(array('id' => 1))->update('table');  



RE: query builder class help - barnent1 - 07-13-2015

You could just set a variable.

Code:
$val = $val + 1;
$this->db->set(array('val' => $val))->where(array('id' => 1))->update('table');



RE: query builder class help - raoh - 07-13-2015

That's right, with the third parameter i can do the update ! it's even on the manual..  Blush

But it doesn't work the query if i give as first parameter an array, second "blank" and third FALSE




The only way is to make value per value like this









PHP Code:
$this->set('field','field+1',FALSE