0

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?

1
  • This question is a bit strange. I cannot imagine creating a library called database in a CodeIgniter application. Is this an XY Problem? Are you actually intending to access the database from a non-Model layer? More context might help to clarify the actual problem. Commented Mar 6 at 23:15

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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.

3 Comments

I wrote config, but it was libraries. I updated the question. Thanks
I assume the missing single quote is also a typo?
let me see your autoload.php config file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.