diff --git a/system/Session/Handlers/DatabaseHandler.php b/system/Session/Handlers/DatabaseHandler.php index a20e2eccda67..4e0b774738f0 100644 --- a/system/Session/Handlers/DatabaseHandler.php +++ b/system/Session/Handlers/DatabaseHandler.php @@ -167,7 +167,7 @@ public function read($sessionID): string $this->sessionID = $sessionID; $builder = $this->db->table($this->table) - ->select('data') + ->select($this->platform === 'postgre' ? "encode(data, 'base64') AS data" : 'data') ->where('id', $sessionID); if ($this->matchIP) @@ -188,9 +188,6 @@ public function read($sessionID): string return ''; } - // PostgreSQL's variant of a BLOB datatype is Bytea, which is a - // PITA to work with, so we use base64-encoded data in a TEXT - // field instead. if (is_bool($result)) { $result = ''; @@ -243,7 +240,7 @@ public function write($sessionID, $sessionData): bool 'id' => $sessionID, 'ip_address' => $this->ipAddress, 'timestamp' => time(), - 'data' => $this->platform === 'postgre' ? base64_encode($sessionData) : $sessionData, + 'data' => $this->platform === 'postgre' ? '\x' . bin2hex($sessionData) : $sessionData, ]; if (! $this->db->table($this->table)->insert($insertData)) @@ -270,7 +267,7 @@ public function write($sessionID, $sessionData): bool if ($this->fingerprint !== md5($sessionData)) { - $updateData['data'] = ($this->platform === 'postgre') ? base64_encode($sessionData) : $sessionData; + $updateData['data'] = ($this->platform === 'postgre') ? '\x' . bin2hex($sessionData) : $sessionData; } if (! $builder->update($updateData)) diff --git a/user_guide_src/source/libraries/sessions.rst b/user_guide_src/source/libraries/sessions.rst index 82172a19db00..feea8eff7f32 100644 --- a/user_guide_src/source/libraries/sessions.rst +++ b/user_guide_src/source/libraries/sessions.rst @@ -596,7 +596,7 @@ For PostgreSQL:: "id" varchar(128) NOT NULL, "ip_address" varchar(45) NOT NULL, "timestamp" bigint DEFAULT 0 NOT NULL, - "data" text DEFAULT '' NOT NULL + "data" bytea DEFAULT '' NOT NULL ); CREATE INDEX "ci_sessions_timestamp" ON "ci_sessions" ("timestamp");