Using the Database for Sessions in CakePHP

Just a quick tip, I've been playing with the new 1.3.3 version of Cake recently and was trying to get the database sessions up and running but had difficultly finding the schema for the sessions table without using the command line to generate the table.

Here's the raw SQL that can be used to create the table. I'm sure it'll be useful in the future for me so I thought I'd share.

CREATE TABLE `cake_sessions` (
  `id` varchar(255) NOT NULL DEFAULT '',
  `data` text,
  `expires` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
);

Now you just need to modify the core.php file so that the database is used for Sessions instead of the default:

Configure::write('Session.save', 'database');

Update

To create the Sessions table from the console simply navigate to the /cake/console directory in the command line and run:

php cake.php schema create Sessions

Posted on 31st August 2010
8 years, 5 months, 3 weeks, 3 days ago

comments powered by Disqus