codeigniter Query Structure Selecting data with second Optional Parameter


Usually we are not using second parameter in select([$select = '*'[, $escape = NULL]]) in CodeIgniter. If you set it to FALSE, CodeIgniter will not try to protect your field or table names.

In the following example, we are going to select the datetime type field by formatting it using sql query and set it FALSE (By doing this, we are going to tell CI not to escape the query automatically).

public function getUserInfo($id)
    $this->db->select(',, DATE_FORMAT(BaseTbl.createdDtm, "%d-%m-%Y") AS createdDtm', FALSE); // FALSE is the second optional parameter
    $this->db->from('tbl_users as BaseTbl');
    $this->db->where('isDeleted', 0);
    $this->db->where('', $id);
    $query = $this->db->get();
    return $query->result();

If we are not set it to FALSE, it will automatically escapes and break the query.