简体   繁体   中英

Incrementing a Table Column, and Getting the New Value using ActiveRecord in CodeIgniter?

I have something similar to the following:

$this->db->set('val', 'val+1', FALSE);
$this->db->where('id', $id);
$query = $this->db->update(TABLE_NAME);

How can I then go, and get the new value of 'val'? Do I have to do another select, or can I get it off of $query ?

I've some experience with CodeIgniter and as far as I know you have to requery again. The update only returns the number of rows affected.

the update query doesnt return anything. if you want to get the value of $val you'll have to run another query

you could run it before running this one, pass the value of val as a parameter to your query next to $id and then return that value + 1.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM