user3569641
user3569641

Reputation: 922

Error on fetching data from Database CodeIgniter

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

Answers (2)

user3569641
user3569641

Reputation: 922

Oh, I forgot to autoload database on autoload.php.

I just added database in$autoload['libraries'] = array('dabatase');`

Upvotes: 1

geggleto
geggleto

Reputation: 2625

You need to setup the database connection in your code igniter config.

This is basically saying the ->db variable is null.

Setup your DB in Code Igniter

Upvotes: 0

Related Questions