aronccs aronccs - 1 year ago 128
SQL Question

Codeigniter update mysql data using increment

I want to add 1 to my column named

(integer), this is my query:

$this->dbsections->update('sections', "SIZE = SIZE + 1");

But in the error message, it reads as:

UPDATE `sections` SET `SIZE = SIZE +` 1 = '' WHERE `NAME` = 'ABC'

Answer Source

You can rewrite your update query

$this->dbsections->set('SIZE', 'SIZE+1', FALSE);// third parameter FALSE
$this->dbsections->where('NAME', "ABC");

set() will also accept an optional third parameter ($escape), that will prevent data from being escaped if set to FALSE