Store your sessions in a different database

Since RC5 it is possible to store the sessions in the database. You can enable that with setting the constant CAKE_SESSION_SAVE in app/config/core.php to “database” (make sure you have created the necessary table with app/config/sql/sessions.sql). By default, you create this session table in the same database which contains your data.

But what to do if you want to separate your data from the session data for some reason? Well, you need two database configurations in app/config/database.php. The “default” configuration must point to the database for the sessions as the session component uses the “default” configuration (it is hardcoded). For the second database configuration you can choose any name. You have to add this name to your app/app_model.php like:

class AppModel extends Model 
{	
    var $useDbConfig = 'mydb';
}

That’s it. Thanks to PhpNut for the explanations, and to alexfill for asking questions.

Post a Comment

Required fields are marked *
*
*

%d bloggers like this: