CodeIgniter Forums

Full Version: Undefined property: Admin::$db when I put database on autoload
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm getting this error when trying to interact with the database with ORM.
Undefined property: Admin::$db

Stack Overflow says I should put database inside the libraries section of autoload.php

I have already done this and I still get the error. It reads 

$autoload['libraries'] = array('database');

Please help.
I might be stating the obvious here but did you add the database credentials to config/database.php ?
I use the above method all the time and never had any issues.

Can you give us any other infos on this?
Yes I did to that yes.

It lets me access the database in the index() method for AdminController but not in the __construct() method in the AdminController

Why would it let me access the database in one method but not other, if I have database autoload on?

I'm using Windows 8.1

Also

Code:
<?php
class Admin extends CI_Controller {

public function __construct()
{
    $this->load->database();  
}
The above code does not work. I get Undefined property: Admin::$load error.
When using a constructor you must first call the parent constuctor of CI_Controller

PHP Code:
public function __construct()
{
    
parent::__construct();
    
$this->load->database();