views:

69

answers:

2

Hello all

I want to implement a SQL statement using codeigniter active record.

UPDATE tags SET usage = usage+1 WHERE tag="java";

How can I implement this using Codeigniter active records?

Regards

+2  A: 
$this->db->set('usage', 'usage+1', FALSE)
$this->db->where('tag', 'java');
$this->db->update('tags');
Phil Sturgeon
Small note on that just to clarify that if you set the optioanl parameter to FALSE, CodeIgniter will not try to protect your field or table names with backticks.
jkilbride
A: 

I find its sometimes simpler to just write the SQL rather than having Active Record build it for me.

$sql = 'update tags set usage=usage+1 where tag=?';
$this->db->query($sql, array($tag));
Stephen Curran