Using CodeIgniter’s framework for query binding is great but can make it hard to debug problems in your SQL statement. The solutions I have come up with is to use the compile_binds function. This will output your SQL statement after the parameters have been cleaned and added.
var_dump($this->db->compile_binds($sql, array($param1, $param2)));