Nisanio
Nisanio

Reputation: 4083

Problem with database in CodeIgniter

I downloaded the last version of CodeIgniter and I tried to run a simple app. The code works perfectly without database, but when I added this

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

the page went to blank.

I looked at the logs files but I didn't find anything, I check differents tutorial, but my database.php file looks correctly configured. I removed it from the array.

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

and added to the controller this:

$this->load->library('database'); 

Then, this error appeared

An Error was encountered

Unable to load the requested class: database

What I do? Any clue?

Thanks in advance

Upvotes: 0

Views: 6068

Answers (2)

jondavidjohn
jondavidjohn

Reputation: 62392

To use the database you need to use the 'library' autoload instead of the 'config' auto load

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

This will actually automatically load up your configurations.

UPDATE

Another thing you mention in your question is that you 'add' that line, you do not need to add that line, you are suppose to add the element to the array that already exists on that line. You potentially could be overwriting other autoloaded libraries, I will need to see your autoload.php file to confirm this.

Upvotes: 2

gen_Eric
gen_Eric

Reputation: 227270

To autoload the database, you use $autoload['libraries'].

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

Or, to load it manually, you use:

$this->load->database();

The database driver is not a normal library, it follows some weird rules.

Upvotes: 5

Related Questions