Update: I wrote a more detailed cookbook for the Symfony2 documentation which is online from today: Documentation
As I told you in my last blog entry, I had the problem that there is no documentation on how to use the PdoSessionStorage in Symfony2. I opened a question on Stackoverflow but there was no one who could help me. Yesterday I found some time to investigate this problem. After reading the Symfony2 sources I found my way. So here it is:
All you need to do is to change some parameters in the app/config/config.yml file (or one of the environment dependend config-files):
session:
default_locale: %locale%
lifetime: 3600
auto_start: true
storage_id: pdo
db_table: session
db_id_col: session_id
db_data_col: session_value
db_time_col: session_time
- db_table: The name of the session table in your database
- db_id_col: The name of the id column in your session table (VARCHAR(255))
- db_data_col: The name of the value column in your session table (TEXT or CLOB)
- db_time_col: The name of the time column in your session table (INTEGER)
Now you have to define a PDO connection in the config.yml. For that create a new service:
services:
pdo_connection:
class: PDO
arguments:
dsn: "mysql:dbname=sf2demo"
user: root
password:
That’s it