I’m unable to load database library in CodeIgniter’s default extracted code
1) via autoload.php
$autoload['libraries'] = array('database');
2) Inside controller via
$this->load->library("database");
or
$CI =& get_instance();
$CI->load->database();
Error message: The page cannot be displayed because an internal server error has occurred.
Environment: CodeIgniter 2.1.3, PHP 5.2.13 on IIS (ISAPI), MySQL (5.0.45-community-nt), Plesk.
I have confirmed that code written in plain PHP allows me to access the database.
As soon as I remove this library, I can see the page. I am able to load other libraries like session, and my custom library as well. Any ideas what I am missing?
Here’re my database config settings:
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'username';
$db['default']['password'] = 'password';
$db['default']['database'] = 'databasename';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
4
Answers
OK, based on the logs, when I set
$db['default']['pconnect'] = TRUE;
to
$db['default']['pconnect'] = FALSE;
the database library got loaded.
you can anyway check your server logs or you can enable CI logs by config.php
go to line 206 of your config.php
put the value to 4 and check if you have a
775 chmod /logs
directory in your/application
folder, if notcreate that
, CI will automatically create log files inside that directory.you’ll be able to check any CI error in this way
AS YOU REPORTED FROM the log file
change, database.php line 50 under /config directory:
to
I had this same issue and spend about 5 hours troubleshooting digging through stack trace and mysql logs. It turns out the cause was unrelated but I am posting here to save anyone the trouble I had.
I build my VM from scratch and I apparently forgot to install the MySQL driver for php5. The symptoms I had are exactly the same, a blank screen – no response at all. To anyone seeing this in the future, make sure you have the mysql driver!! A 30 second fix.
It seems that you do not have your php5-mysql installed.
In your EC2 or your VM, remember to install php5-mysql