Oct
11
Kohana v3 :: Session Database Driver
Leave a comment »
I was having a little trouble getting the session to work while using the database driver (instead of the Native or Cookie drivers), but I eventually found the error. I was using the sessions table MySql create statement from Kohana 2.3 documentation, which is slightly different from the required table for 3.0. So here is a brief tutorial in using the Session with the database driver.
- create the sessions database table (mysql example):
CREATE TABLE `sessions` (
`session_id` varchar(127) NOT NULL,
`last_active` int(10) unsigned NOT NULL,
`contents` text NOT NULL,
PRIMARY KEY (`session_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1; - In the bootstrap.php file, uncomment the line for the database module
- Copy the /modules/database/config/database.php file to /application/config/database.php and fill in the appropriate database connection variables
- to test, create a controller action and run it:
public function action_set()
{
$session = Session::instance('database');
$session->set('foo', 'hello from the session db');
}
- then retrieve the session data in another controller action and run it:
public function action_get()
{
$session = Session::instance('database');
$data = $session->get('foo');
echo Kohana::debug($data);
}
- You should be greated with our session string: ‘hello from the session db’