From faf331007ce5be30f5be514e5cf01d210f5e3b10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20Fern=C3=A1ndez=20Campo?= Date: Fri, 6 Jun 2014 19:13:14 +0200 Subject: [PATCH 1/7] Added DBAL session storaged based on PDO Session storage page --- .../configuration/dbal_session_storage.rst | 134 ++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 cookbook/configuration/dbal_session_storage.rst diff --git a/cookbook/configuration/dbal_session_storage.rst b/cookbook/configuration/dbal_session_storage.rst new file mode 100644 index 00000000000..08f72d7cddb --- /dev/null +++ b/cookbook/configuration/dbal_session_storage.rst @@ -0,0 +1,134 @@ +.. index:: + single: Session; Database Storage + +How to use PdoSessionHandler to store Sessions in the Database +============================================================== + +The default session storage of Symfony2 writes the session information to +file(s). Most medium to large websites use a database to store the session +values instead of files, because databases are easier to use and scale in a +multi-webserver environment. + +Symfony2 has a built-in solution for database session storage called +:class:`Symfony\\Bridge\\Doctrine\\HttpFoundation\\HttpFoundation\\DbalSessionHandler`. +To use it, you just need to inject this class as a service in ``config.yml``: + +.. versionadded:: 2.1 + +.. configuration-block:: + + .. code-block:: yaml + + # app/config/config.yml + framework: + session: + # ... + handler_id: session.handler.dbal_handler + + services: + + session.handler.dbal_handler: + class: Symfony\Bridge\Doctrine\HttpFoundation\DbalSessionHandler + arguments: ["@doctrine.dbal.default_connection"] + + .. code-block:: xml + + + + + + + + + + + + + .. code-block:: php + + // app/config/config.php + use Symfony\Component\DependencyInjection\Definition; + use Symfony\Component\DependencyInjection\Reference; + + $container->loadFromExtension('framework', array( + ..., + 'session' => array( + // ..., + 'handler_id' => 'session.handler.dbal_handler', + ), + )); + + $storageDefinition = new Definition('Symfony\Bridge\Doctrine\HttpFoundation\DbalSessionHandler', array( + new Reference('doctrine.dbal.default_connection'), + )); + $container->setDefinition('session.handler.dbal_handler', $storageDefinition); + +You can pass a second parameter to the constructor to set the table name. +* ``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) or larger) +* ``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) + +Configuring your Database Connection Information +-------------------------------------------- + +With the given configuration, the database connection settings are the ones you've +set for the default doctrine connection. This is OK if you're storing everything +in the same database. If you want to store the sessions in another database you just have +to configure a new doctrine connection. + + +Table structure and example SQL Statements +---------------------- +Because of the way this is implemented in the php class you can only configure the table name (The default is sessions) +Here are a couple of SQL statements to help you create a table that will work with this +MySQL +~~~~~ + +The SQL statement for creating the needed database table might look like the +following (MySQL): + +.. code-block:: sql + + CREATE TABLE `sessions` ( + `sess_id` varchar(255) NOT NULL, + `sess_data` text NOT NULL, + `sess_time` int(11) NOT NULL, + PRIMARY KEY (`sess_id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +PostgreSQL +~~~~~~~~~~ + +For PostgreSQL, the statement should look like this: + +.. code-block:: sql + + CREATE TABLE sessions ( + sess_id character varying(255) NOT NULL, + sess_data text NOT NULL, + sess_time integer NOT NULL, + CONSTRAINT session_pkey PRIMARY KEY (sess_id) + ); + +Microsoft SQL Server +~~~~~~~~~~~~~~~~~~~~ + +For MSSQL, the statement might look like the following: + +.. code-block:: sql + + CREATE TABLE [dbo].[sessions]( + [sess_id] [nvarchar](255) NOT NULL, + [sess_data] [ntext] NOT NULL, + [sess_time] [int] NOT NULL, + PRIMARY KEY CLUSTERED( + [sess_id] ASC + ) WITH ( + PAD_INDEX = OFF, + STATISTICS_NORECOMPUTE = OFF, + IGNORE_DUP_KEY = OFF, + ALLOW_ROW_LOCKS = ON, + ALLOW_PAGE_LOCKS = ON + ) ON [PRIMARY] + ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] From 756a51b0d30b961073b51440aae87572d749e45e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20Fern=C3=A1ndez=20Campo?= Date: Fri, 6 Jun 2014 19:26:25 +0200 Subject: [PATCH 2/7] Fixed bug related to title length --- cookbook/configuration/dbal_session_storage.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cookbook/configuration/dbal_session_storage.rst b/cookbook/configuration/dbal_session_storage.rst index 08f72d7cddb..7634a54cd1f 100644 --- a/cookbook/configuration/dbal_session_storage.rst +++ b/cookbook/configuration/dbal_session_storage.rst @@ -70,7 +70,7 @@ You can pass a second parameter to the constructor to set the table name. * ``db_time_col``: The name of the time column in your session table (INTEGER) Configuring your Database Connection Information --------------------------------------------- +------------------------------------------------- With the given configuration, the database connection settings are the ones you've set for the default doctrine connection. This is OK if you're storing everything @@ -79,7 +79,7 @@ to configure a new doctrine connection. Table structure and example SQL Statements ----------------------- +------------------------------------------ Because of the way this is implemented in the php class you can only configure the table name (The default is sessions) Here are a couple of SQL statements to help you create a table that will work with this MySQL From fb455fb1f43ba16aff367af977fad0f7c8390951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20Fern=C3=A1ndez=20Campo?= Date: Fri, 6 Jun 2014 19:43:45 +0200 Subject: [PATCH 3/7] Fixed bug related to toctree --- cookbook/configuration/index.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/cookbook/configuration/index.rst b/cookbook/configuration/index.rst index 35b87ef0f2e..967245abb90 100644 --- a/cookbook/configuration/index.rst +++ b/cookbook/configuration/index.rst @@ -10,6 +10,7 @@ Configuration front_controllers_and_kernel external_parameters pdo_session_storage + dbal_session_storage apache_router web_server_configuration configuration_organization From 1df0a043c5452a50ce3f885479ff2495684e0457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20Fern=C3=A1ndez=20Campo?= Date: Sat, 20 Sep 2014 20:02:59 +0200 Subject: [PATCH 4/7] - Merged both database session storage configurations into one file --- ...orage.rst => database_session_storage.rst} | 150 +++++++++++++++++- .../configuration/dbal_session_storage.rst | 134 ---------------- cookbook/configuration/index.rst | 4 +- 3 files changed, 146 insertions(+), 142 deletions(-) rename cookbook/configuration/{pdo_session_storage.rst => database_session_storage.rst} (60%) delete mode 100644 cookbook/configuration/dbal_session_storage.rst diff --git a/cookbook/configuration/pdo_session_storage.rst b/cookbook/configuration/database_session_storage.rst similarity index 60% rename from cookbook/configuration/pdo_session_storage.rst rename to cookbook/configuration/database_session_storage.rst index 7955873d878..d12662b0b5f 100644 --- a/cookbook/configuration/pdo_session_storage.rst +++ b/cookbook/configuration/database_session_storage.rst @@ -1,7 +1,11 @@ .. index:: single: Session; Database Storage +<<<<<<< HEAD:cookbook/configuration/pdo_session_storage.rst How to Use PdoSessionHandler to Store Sessions in the Database +======= +How to use Store Session in the Database +>>>>>>> - Merged both database session storage configurations into one file:cookbook/configuration/database_session_storage.rst ============================================================== The default Symfony session storage writes the session information to @@ -9,11 +13,145 @@ file(s). Most medium to large websites use a database to store the session values instead of files, because databases are easier to use and scale in a multi-webserver environment. +<<<<<<< HEAD:cookbook/configuration/pdo_session_storage.rst Symfony has a built-in solution for database session storage called :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\PdoSessionHandler`. To use it, you just need to change some parameters in ``config.yml`` (or the configuration format of your choice): +======= +Symfony2 has two built-in solutions for database session storage one uses doctrine +:class:`Symfony\\Bridge\\Doctrine\\HttpFoundation\\HttpFoundation\\DbalSessionHandler` +and the other uses PDO :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\PdoSessionHandler`. +>>>>>>> - Merged both database session storage configurations into one file:cookbook/configuration/database_session_storage.rst +Using Doctrine to Store the Session in the Database +--------------------------------------------------- + +To use it, you just need to inject this class as a service in ``config.yml``: + +.. versionadded:: 2.1 + +.. configuration-block:: + + .. code-block:: yaml + + # app/config/config.yml + framework: + session: + # ... + handler_id: session.handler.dbal_handler + + services: + + session.handler.dbal_handler: + class: Symfony\Bridge\Doctrine\HttpFoundation\DbalSessionHandler + arguments: ["@doctrine.dbal.default_connection"] + + .. code-block:: xml + + + + + + + + + + + + + .. code-block:: php + + // app/config/config.php + use Symfony\Component\DependencyInjection\Definition; + use Symfony\Component\DependencyInjection\Reference; + + $container->loadFromExtension('framework', array( + ..., + 'session' => array( + // ..., + 'handler_id' => 'session.handler.dbal_handler', + ), + )); + + $storageDefinition = new Definition('Symfony\Bridge\Doctrine\HttpFoundation\DbalSessionHandler', array( + new Reference('doctrine.dbal.default_connection'), + )); + $container->setDefinition('session.handler.dbal_handler', $storageDefinition); + +You can pass a second parameter to the constructor to set the table name. +* ``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) or larger) +* ``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) + +Configuring your Database Connection Information +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +With the given configuration, the database connection settings are the ones you've +set for the default doctrine connection. This is OK if you're storing everything +in the same database. If you want to store the sessions in another database you just have +to configure a new doctrine connection. + + +Table structure and example SQL Statements +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Because of the way this is implemented in the php class you can only configure the table name (The default is sessions) +Here are a couple of SQL statements to help you create a table that will work with this +MySQL +..... + +The SQL statement for creating the needed database table might look like the +following (MySQL): + +.. code-block:: sql + + CREATE TABLE `sessions` ( + `sess_id` varchar(255) NOT NULL, + `sess_data` text NOT NULL, + `sess_time` int(11) NOT NULL, + PRIMARY KEY (`sess_id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +PostgreSQL +.......... + +For PostgreSQL, the statement should look like this: + +.. code-block:: sql + + CREATE TABLE sessions ( + sess_id character varying(255) NOT NULL, + sess_data text NOT NULL, + sess_time integer NOT NULL, + CONSTRAINT session_pkey PRIMARY KEY (sess_id) + ); + +Microsoft SQL Server +.................... + +For MSSQL, the statement might look like the following: + +.. code-block:: sql + + CREATE TABLE [dbo].[sessions]( + [sess_id] [nvarchar](255) NOT NULL, + [sess_data] [ntext] NOT NULL, + [sess_time] [int] NOT NULL, + PRIMARY KEY CLUSTERED( + [sess_id] ASC + ) WITH ( + PAD_INDEX = OFF, + STATISTICS_NORECOMPUTE = OFF, + IGNORE_DUP_KEY = OFF, + ALLOW_ROW_LOCKS = ON, + ALLOW_PAGE_LOCKS = ON + ) ON [PRIMARY] + ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] + + +Using PDO to Store the Session in the Database +---------------------------------------------- .. versionadded:: 2.1 In Symfony 2.1 the class and namespace are slightly modified. You can now find the session storage classes in the ``Session\Storage`` namespace: @@ -126,7 +264,7 @@ configuration format of your choice): * ``db_time_col``: The name of the time column in your session table (INTEGER) Sharing your Database Connection Information --------------------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ With the given configuration, the database connection settings are defined for the session storage connection only. This is OK when you use a separate @@ -165,10 +303,10 @@ of your project's data, you can use the connection settings from the )); Example SQL Statements ----------------------- +~~~~~~~~~~~~~~~~~~~~~~ MySQL -~~~~~ +..... The SQL statement for creating the needed database table might look like the following (MySQL): @@ -183,7 +321,7 @@ following (MySQL): ) ENGINE=InnoDB DEFAULT CHARSET=utf8; PostgreSQL -~~~~~~~~~~ +.......... For PostgreSQL, the statement should look like this: @@ -197,7 +335,7 @@ For PostgreSQL, the statement should look like this: ); Microsoft SQL Server -~~~~~~~~~~~~~~~~~~~~ +.................... For MSSQL, the statement might look like the following: @@ -216,4 +354,4 @@ For MSSQL, the statement might look like the following: ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] - ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] + ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] \ No newline at end of file diff --git a/cookbook/configuration/dbal_session_storage.rst b/cookbook/configuration/dbal_session_storage.rst deleted file mode 100644 index 7634a54cd1f..00000000000 --- a/cookbook/configuration/dbal_session_storage.rst +++ /dev/null @@ -1,134 +0,0 @@ -.. index:: - single: Session; Database Storage - -How to use PdoSessionHandler to store Sessions in the Database -============================================================== - -The default session storage of Symfony2 writes the session information to -file(s). Most medium to large websites use a database to store the session -values instead of files, because databases are easier to use and scale in a -multi-webserver environment. - -Symfony2 has a built-in solution for database session storage called -:class:`Symfony\\Bridge\\Doctrine\\HttpFoundation\\HttpFoundation\\DbalSessionHandler`. -To use it, you just need to inject this class as a service in ``config.yml``: - -.. versionadded:: 2.1 - -.. configuration-block:: - - .. code-block:: yaml - - # app/config/config.yml - framework: - session: - # ... - handler_id: session.handler.dbal_handler - - services: - - session.handler.dbal_handler: - class: Symfony\Bridge\Doctrine\HttpFoundation\DbalSessionHandler - arguments: ["@doctrine.dbal.default_connection"] - - .. code-block:: xml - - - - - - - - - - - - - .. code-block:: php - - // app/config/config.php - use Symfony\Component\DependencyInjection\Definition; - use Symfony\Component\DependencyInjection\Reference; - - $container->loadFromExtension('framework', array( - ..., - 'session' => array( - // ..., - 'handler_id' => 'session.handler.dbal_handler', - ), - )); - - $storageDefinition = new Definition('Symfony\Bridge\Doctrine\HttpFoundation\DbalSessionHandler', array( - new Reference('doctrine.dbal.default_connection'), - )); - $container->setDefinition('session.handler.dbal_handler', $storageDefinition); - -You can pass a second parameter to the constructor to set the table name. -* ``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) or larger) -* ``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) - -Configuring your Database Connection Information -------------------------------------------------- - -With the given configuration, the database connection settings are the ones you've -set for the default doctrine connection. This is OK if you're storing everything -in the same database. If you want to store the sessions in another database you just have -to configure a new doctrine connection. - - -Table structure and example SQL Statements ------------------------------------------- -Because of the way this is implemented in the php class you can only configure the table name (The default is sessions) -Here are a couple of SQL statements to help you create a table that will work with this -MySQL -~~~~~ - -The SQL statement for creating the needed database table might look like the -following (MySQL): - -.. code-block:: sql - - CREATE TABLE `sessions` ( - `sess_id` varchar(255) NOT NULL, - `sess_data` text NOT NULL, - `sess_time` int(11) NOT NULL, - PRIMARY KEY (`sess_id`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -PostgreSQL -~~~~~~~~~~ - -For PostgreSQL, the statement should look like this: - -.. code-block:: sql - - CREATE TABLE sessions ( - sess_id character varying(255) NOT NULL, - sess_data text NOT NULL, - sess_time integer NOT NULL, - CONSTRAINT session_pkey PRIMARY KEY (sess_id) - ); - -Microsoft SQL Server -~~~~~~~~~~~~~~~~~~~~ - -For MSSQL, the statement might look like the following: - -.. code-block:: sql - - CREATE TABLE [dbo].[sessions]( - [sess_id] [nvarchar](255) NOT NULL, - [sess_data] [ntext] NOT NULL, - [sess_time] [int] NOT NULL, - PRIMARY KEY CLUSTERED( - [sess_id] ASC - ) WITH ( - PAD_INDEX = OFF, - STATISTICS_NORECOMPUTE = OFF, - IGNORE_DUP_KEY = OFF, - ALLOW_ROW_LOCKS = ON, - ALLOW_PAGE_LOCKS = ON - ) ON [PRIMARY] - ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] diff --git a/cookbook/configuration/index.rst b/cookbook/configuration/index.rst index 967245abb90..69329b00ea9 100644 --- a/cookbook/configuration/index.rst +++ b/cookbook/configuration/index.rst @@ -9,8 +9,8 @@ Configuration using_parameters_in_dic front_controllers_and_kernel external_parameters - pdo_session_storage - dbal_session_storage + database_session_storage + apache_router web_server_configuration configuration_organization From 779f8f7ba40a67fa6f682b2e76cdf95e01c6e557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20Fern=C3=A1ndez=20Campo?= Date: Thu, 2 Oct 2014 23:25:15 +0200 Subject: [PATCH 5/7] Removed reference to config.yml --- .../configuration/database_session_storage.rst | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/cookbook/configuration/database_session_storage.rst b/cookbook/configuration/database_session_storage.rst index d12662b0b5f..48642964710 100644 --- a/cookbook/configuration/database_session_storage.rst +++ b/cookbook/configuration/database_session_storage.rst @@ -1,35 +1,23 @@ .. index:: single: Session; Database Storage -<<<<<<< HEAD:cookbook/configuration/pdo_session_storage.rst -How to Use PdoSessionHandler to Store Sessions in the Database -======= -How to use Store Session in the Database ->>>>>>> - Merged both database session storage configurations into one file:cookbook/configuration/database_session_storage.rst -============================================================== +How to Store Session in the Database +==================================== The default Symfony session storage writes the session information to file(s). Most medium to large websites use a database to store the session values instead of files, because databases are easier to use and scale in a multi-webserver environment. -<<<<<<< HEAD:cookbook/configuration/pdo_session_storage.rst -Symfony has a built-in solution for database session storage called -:class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\PdoSessionHandler`. -To use it, you just need to change some parameters in ``config.yml`` (or the -configuration format of your choice): -======= Symfony2 has two built-in solutions for database session storage one uses doctrine :class:`Symfony\\Bridge\\Doctrine\\HttpFoundation\\HttpFoundation\\DbalSessionHandler` and the other uses PDO :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\PdoSessionHandler`. ->>>>>>> - Merged both database session storage configurations into one file:cookbook/configuration/database_session_storage.rst Using Doctrine to Store the Session in the Database --------------------------------------------------- -To use it, you just need to inject this class as a service in ``config.yml``: +To use it, you just need to inject this class as a service in the configuration: -.. versionadded:: 2.1 .. configuration-block:: From e2ce2175ce5daa4cf0eddd1e88ef5ce811d50b44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20Fern=C3=A1ndez=20Campo?= Date: Mon, 9 Mar 2015 21:03:41 +0100 Subject: [PATCH 6/7] - Implemented changes related the latest comments --- .../database_session_storage.rst | 10 +- .../configuration/dbal_session_storage.rst | 134 ++++++++++++++++++ cookbook/configuration/index.rst | 1 + 3 files changed, 142 insertions(+), 3 deletions(-) create mode 100644 cookbook/configuration/dbal_session_storage.rst diff --git a/cookbook/configuration/database_session_storage.rst b/cookbook/configuration/database_session_storage.rst index 48642964710..9b29df00f87 100644 --- a/cookbook/configuration/database_session_storage.rst +++ b/cookbook/configuration/database_session_storage.rst @@ -16,9 +16,10 @@ and the other uses PDO :class:`Symfony\\Component\\HttpFoundation\\Session\\Stor Using Doctrine to Store the Session in the Database --------------------------------------------------- -To use it, you just need to inject this class as a service in the configuration: +To use The DBAL session storage, you need to register a new service and configure + Symfony's session handling to use it: + - .. configuration-block:: .. code-block:: yaml @@ -81,8 +82,11 @@ set for the default doctrine connection. This is OK if you're storing everything in the same database. If you want to store the sessions in another database you just have to configure a new doctrine connection. +.. note:: + + How to configure multiple entity managers is covered in the :doc:`/cookbook/doctrine/multiple_entity_managers` page of the book. -Table structure and example SQL Statements +Table Structure and Example SQL Statements ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Because of the way this is implemented in the php class you can only configure the table name (The default is sessions) Here are a couple of SQL statements to help you create a table that will work with this diff --git a/cookbook/configuration/dbal_session_storage.rst b/cookbook/configuration/dbal_session_storage.rst new file mode 100644 index 00000000000..a1f1b7a7b3f --- /dev/null +++ b/cookbook/configuration/dbal_session_storage.rst @@ -0,0 +1,134 @@ +.. index:: + single: Session; Database Storage + +How to use PdoSessionHandler to Store Session in the Database +============================================================== + +The default session storage of Symfony2 writes the session information to +file(s). Most medium to large websites use a database to store the session +values instead of files, because databases are easier to use and scale in a +multi-webserver environment. + +Symfony2 has a built-in solution for database session storage called +:class:`Symfony\\Bridge\\Doctrine\\HttpFoundation\\HttpFoundation\\DbalSessionHandler`. +To use it, you just need to inject this class as a service in ``config.yml``: + +.. versionadded:: 2.1 + +.. configuration-block:: + + .. code-block:: yaml + + # app/config/config.yml + framework: + session: + # ... + handler_id: session.handler.dbal_handler + + services: + + session.handler.dbal_handler: + class: Symfony\Bridge\Doctrine\HttpFoundation\DbalSessionHandler + arguments: ["@doctrine.dbal.default_connection"] + + .. code-block:: xml + + + + + + + + + + + + + .. code-block:: php + + // app/config/config.php + use Symfony\Component\DependencyInjection\Definition; + use Symfony\Component\DependencyInjection\Reference; + + $container->loadFromExtension('framework', array( + ..., + 'session' => array( + // ..., + 'handler_id' => 'session.handler.dbal_handler', + ), + )); + + $storageDefinition = new Definition('Symfony\Bridge\Doctrine\HttpFoundation\DbalSessionHandler', array( + new Reference('doctrine.dbal.default_connection'), + )); + $container->setDefinition('session.handler.dbal_handler', $storageDefinition); + +You can pass a second parameter to the constructor to set the table name. +* ``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) or larger) +* ``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) + +Configuring your Database Connection Information +------------------------------------------------- + +With the given configuration, the database connection settings are the ones you've +set for the default doctrine connection. This is OK if you're storing everything +in the same database. If you want to store the sessions in another database you just have +to configure a new doctrine connection. + + +Table structure and example SQL Statements +------------------------------------------ +Because of the way this is implemented in the php class you can only configure the table name (The default is sessions) +Here are a couple of SQL statements to help you create a table that will work with this +MySQL +~~~~~ + +The SQL statement for creating the needed database table might look like the +following (MySQL): + +.. code-block:: sql + + CREATE TABLE `sessions` ( + `sess_id` varchar(255) NOT NULL, + `sess_data` text NOT NULL, + `sess_time` int(11) NOT NULL, + PRIMARY KEY (`sess_id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +PostgreSQL +~~~~~~~~~~ + +For PostgreSQL, the statement should look like this: + +.. code-block:: sql + + CREATE TABLE sessions ( + sess_id character varying(255) NOT NULL, + sess_data text NOT NULL, + sess_time integer NOT NULL, + CONSTRAINT session_pkey PRIMARY KEY (sess_id) + ); + +Microsoft SQL Server +~~~~~~~~~~~~~~~~~~~~ + +For MSSQL, the statement might look like the following: + +.. code-block:: sql + + CREATE TABLE [dbo].[sessions]( + [sess_id] [nvarchar](255) NOT NULL, + [sess_data] [ntext] NOT NULL, + [sess_time] [int] NOT NULL, + PRIMARY KEY CLUSTERED( + [sess_id] ASC + ) WITH ( + PAD_INDEX = OFF, + STATISTICS_NORECOMPUTE = OFF, + IGNORE_DUP_KEY = OFF, + ALLOW_ROW_LOCKS = ON, + ALLOW_PAGE_LOCKS = ON + ) ON [PRIMARY] + ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] diff --git a/cookbook/configuration/index.rst b/cookbook/configuration/index.rst index 69329b00ea9..581546b9192 100644 --- a/cookbook/configuration/index.rst +++ b/cookbook/configuration/index.rst @@ -14,3 +14,4 @@ Configuration apache_router web_server_configuration configuration_organization + cookbook/configuration/pdo_session_storage cookbook/configuration/database_session_storage From caef279533bfb62608f92d8206311844862844db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20Fern=C3=A1ndez=20Campo?= Date: Sun, 15 Mar 2015 13:55:14 +0100 Subject: [PATCH 7/7] - Modified database_session_storage to fit the style guide - Added an entry into the redirection_map --- .../configuration/database_session_storage.rst | 16 ++++++++++------ redirection_map | 1 + 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/cookbook/configuration/database_session_storage.rst b/cookbook/configuration/database_session_storage.rst index 9b29df00f87..4f4468e7392 100644 --- a/cookbook/configuration/database_session_storage.rst +++ b/cookbook/configuration/database_session_storage.rst @@ -18,8 +18,6 @@ Using Doctrine to Store the Session in the Database To use The DBAL session storage, you need to register a new service and configure Symfony's session handling to use it: - - .. configuration-block:: .. code-block:: yaml @@ -69,10 +67,15 @@ To use The DBAL session storage, you need to register a new service and configur $container->setDefinition('session.handler.dbal_handler', $storageDefinition); You can pass a second parameter to the constructor to set the table name. -* ``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) or larger) -* ``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) + +``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) or larger) +``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) Configuring your Database Connection Information ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -88,6 +91,7 @@ to configure a new doctrine connection. Table Structure and Example SQL Statements ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + Because of the way this is implemented in the php class you can only configure the table name (The default is sessions) Here are a couple of SQL statements to help you create a table that will work with this MySQL diff --git a/redirection_map b/redirection_map index 2d782f924fb..9b2a958d2b0 100644 --- a/redirection_map +++ b/redirection_map @@ -23,3 +23,4 @@ /cookbook/console/generating_urls /cookbook/console/sending_emails /components/yaml /components/yaml/introduction /components/templating /components/templating/introduction +/cookbook/configuration/pdo_session_storage /cookbook/configuration/database_session_storage