http://ellislab.com/codeigniter/user-guide/database/queries.html
"...benefit of using binds is that the values are automatically escaped..."
Of note, Query Bindings
looks like the easiest method:
$this->db->query( " SELECT id FROM users WHERE username = ? AND age = ? ", array ( 'todd', '37' ) );
###Query Bindings
Bindings enable you to simplify your query syntax by letting the system put the queries together for you. Consider the following example:
$sql = "SELECT * FROM some_table WHERE id = ? AND status = ? AND author = ?";
$this->db->query($sql, array(3, 'live', 'Rick'));
The question marks in the query are automatically replaced with the values in the array in the second parameter of the query function.
The secondary benefit of using binds is that the values are automatically escaped, producing safer queries. You don't have to remember to manually escape data; the engine does it automatically for you.