skip to Main Content

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


  1. Chosen as BEST ANSWER

    OK, based on the logs, when I set

    $db['default']['pconnect'] = TRUE;

    to

    $db['default']['pconnect'] = FALSE;

    the database library got loaded.


  2. you can anyway check your server logs or you can enable CI logs by config.php

    go to line 206 of your config.php

    /*
    |--------------------------------------------------------------------------
    | Error Logging Threshold
    |--------------------------------------------------------------------------
    |
    | If you have enabled error logging, you can set an error threshold to
    | determine what gets logged. Threshold options are:
    | You can enable error logging by setting a threshold over zero. The
    | threshold determines what gets logged. Threshold options are:
    |
    |   0 = Disables logging, Error logging TURNED OFF
    |   1 = Error Messages (including PHP errors)
    |   2 = Debug Messages
    |   3 = Informational Messages
    |   4 = All Messages
    |
    | For a live site you'll usually only enable Errors (1) to be logged otherwise
    | your log files will fill up very fast.
    |
    */
    $config['log_threshold'] = 4;
    

    put the value to 4 and check if you have a 775 chmod /logs directory in your /application folder, if not create 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:

    $db['default']['pconnect'] = TRUE;
    

    to

    $db['default']['pconnect'] = FALSE;
    
    Login or Signup to reply.
  3. 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.

    Login or Signup to reply.
  4. It seems that you do not have your php5-mysql installed.
    In your EC2 or your VM, remember to install php5-mysql

    sudo apt-get install php5-mysql

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search