Reputation: 922
I am new to CodeIgniter and I have a problem when fetching data from database. 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
. Please help me.
Upvotes: 1
Views: 116
Reputation: 922
Oh, I forgot to autoload database on autoload.php
.
I just added database in
$autoload['libraries'] = array('dabatase');`
Upvotes: 1
Reputation: 2625
You need to setup the database connection in your code igniter config.
This is basically saying the ->db variable is null.
Upvotes: 0