I have a get dunction inside a MY_Model I'm trying to create, which returns either a single record or all records. What I'd like to do is when I get the result(s) to ALWAYS free some memory with free_result(), but if i put it in the line i return the result, I got nothing. Any suggestions please?
public function get($id = NULL, $single = FALSE){
if ($id != NULL) {
$filter = $this->_primary_filter; // filter the id
$id = $filter($id); // e.g. intval($id)
$this->db->where($this->_primary_key, $id);
$method = 'row'; // single record
} elseif ($single === TRUE) {
$method = 'row'; // single record
} else {
$method = 'result'; // all records
}
return $this->db->get($this->_table_name)->$method();
}