views:

20

answers:

2

Fatal error: Call to a member function result() on a non-object in C:\wamp\www\system\application\models\users_model.php on line 8

   <?php

    class Users_model extends Model {

      function get_records()
      {
        $query = $this->db->get('users');
        return $query->result();
      }

    }
    ?>
+2  A: 

The above error is occuring because the value of $query is NULL or a non-object. This is likely because get('users') failed to return a proper query.

Make sure your database has a table users and that your database library is initialized and configured correctly.

Aren
I have tried 2 live databases, (not local) and I still get the same error. I also tried different setups of code from multiple tutorials all leading to the same error. What could it be?
ThomasReggi
+1  A: 

I agree with Aren.

You should implement some sort of failure checking to gracefully handle this error.

$result = $this->Users_model->get_records();
if ($result == null)
  echo "error message";
else
{
  // do your normal page handling
}
espais