开发者

codeigniter fatal error, trying to read database

开发者 https://www.devze.com 2023-01-03 16:37 出处:网络
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

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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消