Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
2
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

@0828

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

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

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

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が入る場合にそうなるらしい。

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;
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
2
Help us understand the problem. What are the problem?