[英]Error on fetching data from Database CodeIgniter
I am new to CodeIgniter and I have a problem when fetching data from database. 我是CodeIgniter的新手,从数据库中获取数据时遇到问题。 How can I fix this?
我怎样才能解决这个问题? My code is
我的代码是
class Disaster_model extends CI_Model
{
public function __construct()
{
parent::__construct();
$this->table = 'disasters';
}
public function lists()
{
$data = $this->db->get($this->table);
return json_encode($data->result());
}
}
The errors are: Undefined property: Disaster::$db
and Call to a member function get() on null
. 错误为:
Undefined property: Disaster::$db
和Call to a member function get() on null
。 Please help me. 请帮我。
Oh, I forgot to autoload database on autoload.php
. 哦,我忘了在autoload.php上
autoload.php
加载数据库。
I just added database in
$autoload['libraries'] = array('dabatase');` 我刚刚
database in
$ autoload ['libraries'] = array('dabatase');中添加了database in
。
You need to setup the database connection in your code igniter config. 您需要在代码点火器配置中设置数据库连接。
This is basically saying the ->db variable is null. 这基本上是说-> db变量为null。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.