php – codeigniter database cache configuration-ThrowExceptions

Exception or error:

I’m unable to configure database cache to my system. I’ve tried every configuration that available in internet . please help me out.

$db['default'] = array(
'dsn'   => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '123',
'database' => 'test',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => TRUE,
'cachedir' => 'application/cache',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt'  => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
    'save_queries' => TRUE

Below is the error message that i’m getting

An uncaught Exception was encountered

Type: Exception

Message: Configured database connection has cache enabled. Aborting.

Filename: C:\wamp\www\test\system\libraries\Session\drivers\Session_database_driver.php

How to solve:

Caching is enabled in three steps:

1) Create a writable directory on your server where the cache files can be stored.

2) Set the path to your cache folder in your application/config/database.php file.
For Example :

$db['default']['hostname'] = 'XXXXX';
$db['default']['username'] = 'XXXXX';
$db['default']['password'] = 'XXXXX';
$db['default']['database'] = 'XXXXX';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = 'XXX';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = TRUE;
$db['default']['cachedir'] = 'application/cache';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

3) Enable the caching feature, either globally by setting the preference in your application/config/database.php file, or
Manually enables/disables caching as described below.

 // Turn caching on

 // Turn caching off for this one query

Also, make sure your directory is writable (if you are on Mac or Linux)

sudo chmod 777 -R application/cache

I hope it will work for you.


I have to modify the db_cache class as follows

vi +146 /var/www/html/sys/database/DB_cache.php


    return FALSE;

Leave a Reply

Your email address will not be published. Required fields are marked *