daryl
daryl

Reputation: 15197

Connecting to the database in a Created Library - CodeIgniter

I have a little issue right now and its bugging me, hopefully one of you guys will be able to help me out.

Basically I'm creating a library to use in CodeIgniter and I'm getting this error:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Functions::$db

Filename: libraries/Functions.php

Line Number: 11

The Database library is already on autoload aswell as my functions library:

$autoload['libraries'] = array('database','session','encrypt','functions');

The Functions.php file is located in the application/libraries folder accordingly.

Line number 11 consists of this:

$this->db->where('username', $data);

Not sure as to why the db is an undefined property?

Upvotes: 1

Views: 5306

Answers (1)

Shomz
Shomz

Reputation: 37701

It's probably because you need to get the CI instance first since not everything is loaded yet:

$ci =& get_instance();
$ci->db->where('username', $data);

See if that helps. Also see the instructions here.

Upvotes: 4

Related Questions