I'm trying to execute a SQL query directly from Model in CI 4
Controller:
$homemodel = new \App\Models\home_model();
$data['list'] = $homemodel->myquery();
Model:
public function myquery(){
$query = "SELECT id FROM tab_anagr WHERE var = 1";
$query=$this->db->query($query);
return $query->result_array();
}
Does'nt work and I receive this error:
Call to undefined method CodeIgniter\Database\MySQLi\Result::result_array()
I would like to receive the array for the view.
You should use $query->getResultArray()
to get the result as an array, if you want it as object you can use $query->getResult()