Help us understand the problem. What is going on with this article?

CakePHP3のデータベースセッションにすると"Failed to decode session object."と言われる

More than 3 years have passed since last update.

CakePHP3を使ってて、セッション管理をDBにしたくて、

http://book.cakephp.org/3.0/ja/development/sessions.html#id5

に書かれている通りにしたのです。

config/schema/sessions.sql
CREATE TABLE sessions (
  id varchar(40) NOT NULL default '',
  data text,
  expires INT(11) NOT NULL,
  PRIMARY KEY  (id)
);
config/app.php
'Session' => [
    'defaults' => 'database'
]

そしたら、

session_start(): Failed to decode session object. Session has been destroyed in [/path/to/vendor/cakephp/cakephp/src/Network/Session.php, line 325]

というエラー。

色々調べた結果、sessionsテーブルにmulti-byteが入る場合にそうなるらしい。

http://stackoverflow.com/questions/33051842/session-start-is-not-success-when-use-multi-byte-into-the-session-in-cakephp3

sessionsテーブルをutf8で作り直したらエラーが出なくなりました。

config/schema/sessions.sql
CREATE TABLE sessions (
  id varchar(40) NOT NULL default '',
  data text,
  expires INT(11) NOT NULL,
  PRIMARY KEY  (id)
) CHARSET=utf8;
0828
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした