CodeIgniter Query Helper

CodeIgniter's comes with following Query Helper Functions.


Return insert ID number while we performing database inserts.


Return number of affected rows.when we performing insert, update, etc.

Note:MySQL DELETE operation returns 0 affected rows.


Return number of rows in a particular table.Pass table name as parameter.

echo $this->db->count_all('table_name'); //Output:10


Return platform you are running (MySQL, MS SQL, Postgres, etc...)

echo $this->db->platform(); //Output:MySQL


Return the database version you are running.


Return the last query (the query string, not the result).

$sql = $this->db->last_query(); // Output: SELECT * FROM table_name


Return formatted SQL insert string.

$data = array('name' => $name, 'email' => $email); $sql = $this->db->insert_string('table_name', $data); // Output: INSERT INTO table_name (name, email) VALUES ('Roje', '[email protected]')


Return formatted SQL update string.

$data = array('name' => $name, 'email' => $email); $where = "id = 1"; $sql= $this->db->update_string('table_name', $data, $where); // Output:UPDATE table_name SET name = 'Rose', email = '[email protected]' WHERE id = 1