Skip to content

Commit 52a2372

Browse files
authored
Merge pull request #7596 from kenjis/docs-db-session
docs: improve "Configure DatabaseHandler" for Session
2 parents 9d9f19e + 963526a commit 52a2372

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

user_guide_src/source/libraries/sessions.rst

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,9 @@ However, there are some conditions that must be met:
559559
Configure DatabaseHandler
560560
-------------------------
561561

562+
Setting Table Name
563+
^^^^^^^^^^^^^^^^^^
564+
562565
In order to use the 'DatabaseHandler' session driver, you must also create this
563566
table that we already mentioned and then set it as your
564567
``$savePath`` value.
@@ -567,6 +570,9 @@ you would do this:
567570

568571
.. literalinclude:: sessions/039.php
569572

573+
Creating Database Table
574+
^^^^^^^^^^^^^^^^^^^^^^^
575+
570576
And then of course, create the database table ...
571577

572578
For MySQL::
@@ -594,6 +600,9 @@ For PostgreSQL::
594600
and the session ID and a delimiter. It should be increased as needed, for example,
595601
when using long session IDs.
596602

603+
Adding Primary Key
604+
^^^^^^^^^^^^^^^^^^
605+
597606
You will also need to add a PRIMARY KEY **depending on your $matchIP
598607
setting**. The examples below work both on MySQL and PostgreSQL::
599608

@@ -606,11 +615,23 @@ setting**. The examples below work both on MySQL and PostgreSQL::
606615
// To drop a previously created primary key (use when changing the setting)
607616
ALTER TABLE ci_sessions DROP PRIMARY KEY;
608617

609-
You can choose the Database group to use by adding a new line to the
610-
**app/Config/Session.php** file with the name of the group to use:
618+
.. important:: If you don't add the correct primary key, the following error
619+
may occur::
620+
621+
Uncaught mysqli_sql_exception: Duplicate entry 'ci_session:***' for key 'ci_sessions.PRIMARY'
622+
623+
Changing Database Group
624+
^^^^^^^^^^^^^^^^^^^^^^^
625+
626+
The default database group is used by default.
627+
You can change the database group to use by changing the ``$DBGroup`` property
628+
in the **app/Config/Session.php** file to the name of the group to use:
611629

612630
.. literalinclude:: sessions/040.php
613631

632+
Setting Up Database Table with Command
633+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
634+
614635
If you'd rather not do all of this by hand, you can use the ``make:migration --session`` command
615636
from the cli to generate a migration file for you::
616637

user_guide_src/source/libraries/sessions/040.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,4 @@ class Session extends BaseConfig
99
{
1010
// ...
1111
public ?string $DBGroup = 'groupName';
12-
13-
// ...
1412
}

0 commit comments

Comments
 (0)