If you need to programatically build your query CodeIgniter's Active Records are far more comfortable than plain text,
$id = 2;
//with CodeIgniter's Active Record
$this->db->select('title, contents');
$this->db->from('data');
if(isset($id))
$this->db->where('id', $id);
//without CodeIgniter's Active Record
if(isset($id))
$where = " WHERE id = {$id}";
$this->db->query(" SELECT title, contents FROM data".$where);
Ok, this isn't changing that much but what if you have 10 constraints on the where clause?
furthermore CodeIgniter's Active Record build the string in the right way (with placeholders ?
) according to the data you pass i.e. you won't have to insert the '
manually on the query.
EDIT
@Col. Shrapnel said that there are no benefits with CodeIgniter's Active Record, since I'm not in agree with him I try to enforce my thesis with another example:
Let's do an example for an INSERT statement:
$array = array('A'=>'aaaa','B'=>'bbbb','C'=>'cccc');
//without CodeIgniter's Active Record
$query = "INSERT INTO my_table (";
$query.= implode(',',array_keys($array)) .')';
$query.= ......
//with CodeIgniter's Active Record
$this->db->insert('my_table',$array);