Search code examples
phpcodeignitercodeigniter-3codeigniter-query-builder

select query doesn't give result in codeigniter?


Select query don't show records array.

Below is my get_all_user method code.

public  function get_all_user(){

 $query = $this->db->query("select * from user");
 echo"<pre/>";print_r($query);die;
}

when i print $query it shows result_array() empty. Please help me to solve this problem.


Solution

  • Should be like this :

    public function get_all_user()
    {
      $query = $this->db->query("select * from user");
      $results = $query->result();
      echo"<pre/>";print_r($results);die;
    }
    

    Or You can simply do like this :

    public function get_all_user()
    {
      $results = $this->db->get("user")->result();
      print_r($results);die;
    }
    

    For more : https://www.codeigniter.com/user_guide/database/query_builder.html