codeigniter-base-model
codeigniter-base-model copied to clipboard
Select specific fields
Hi,
How can you return only selected fields using all get functions (get(), get_by(), get_many(), get_many_by() and get_all()). Fetching all the columns of the database/record is not that fast or ideal I believe. Though I can do a filtering of the returned object data but still the delay was already made during the query. I how you can give me an advice on how to make this happen. Thank you in advance.
write method
public function select($what = '*', $escape = true) {
$this->_database->select($what, $escape); return $this;
}
usage
$this->article_model->select('id, title')->get_all();
Thanks for the suggestion michail1982, I'll take note of this and try it out. :+1:
public function your_select(){ $this->db->select('id,field1,field2'); return $this; }
$this->article_model->your_select()->get_all();