codeigniter fatal error, trying to read database
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 {
funct开发者_JAVA百科ion get_records()
{
$query = $this->db->get('users');
return $query->result();
}
}
?>
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.
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
}
精彩评论