CodeIgniter - Call to a member function select() on a non-object
codeigniter, php
Solution
I think that you have to load the "database" library. The first way is to include the "database" in your application/config/autoload.php
$autoload['libraries'] = array('database', 'session');
or in your class constructor:
class User_model extends CI_Model {
public function __construct()
{
parent::__construct();
$this->load->database();
}
}
You can get more information here: https://www.codeigniter.com/user_guide/database/connecting.html
Problem
I'm quite new to CodeIgniter. This is my code: ``` class User_model extends CI_Model { function validate_user() { $this->db->select('*'); $this->db->from('user'); $this->db->where('username', $this->input->post('username')); $this->db->where('password', md5($this->input->post('password'))); $validate_user = $this->db->get(); if($validate_user->num_rows == 1) { return TRUE; } } } ``` I'm, receiving this error in my model file: ``` Call to a member function select() on a non-object ``` Currently I'm using CodeIgniter version 2.1.0. Please help me!