【问题标题】:codeigniter fatal error, trying to read databasecodeigniter 致命错误,试图读取数据库
【发布时间】:2010-06-18 04:07:46
【问题描述】:

致命错误:在第 8 行对 C:\wamp\www\system\application\models\users_model.php 中的非对象调用成员函数 result()

   <?php

    class Users_model extends Model {

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

    }
    ?>

【问题讨论】:

    标签: php mysql html codeigniter


    【解决方案1】:

    出现上述错误是因为$query 的值为NULL 或非对象。这可能是因为get('users') 未能返回正确的查询。

    确保您的数据库有一个表users,并且您的数据库库已正确初始化和配置。

    【讨论】:

    • 我已经尝试了 2 个实时数据库(不是本地数据库),但仍然出现同样的错误。我还尝试了来自多个教程的不同代码设置,所有这些都导致相同的错误。会是什么?
    【解决方案2】:

    我同意阿伦。

    您应该实施某种故障检查来优雅地处理此错误。

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

    【讨论】:

      猜你喜欢
      • 2020-02-21
      • 1970-01-01
      • 1970-01-01
      • 2014-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多