diff --git a/Session/Storage/Handler/PdoSessionHandler.php b/Session/Storage/Handler/PdoSessionHandler.php index 47d412ea368..7ffa3660d19 100644 --- a/Session/Storage/Handler/PdoSessionHandler.php +++ b/Session/Storage/Handler/PdoSessionHandler.php @@ -194,6 +194,7 @@ public function configureSchema(Schema $schema, ?\Closure $isSameDatabase = null $table->addColumn($this->dataCol, Types::BLOB)->setNotnull(true); $table->addColumn($this->lifetimeCol, Types::INTEGER)->setUnsigned(true)->setNotnull(true); $table->addColumn($this->timeCol, Types::INTEGER)->setUnsigned(true)->setNotnull(true); + $table->addOption('charset', 'utf8mb4'); $table->addOption('collate', 'utf8mb4_bin'); $table->addOption('engine', 'InnoDB'); break; diff --git a/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php b/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php index d44fdd17598..cc61855e3d4 100644 --- a/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php @@ -356,6 +356,22 @@ public function testConfigureSchemaTableExistsPdo() $this->assertEmpty($table->getColumns(), 'The table was not overwritten'); } + public function testConfigureSchemaSetsUtf8mb4CharsetForMysql() + { + $pdo = new MockPdo('mysql'); + $pdo->prepareResult = $this->createMock(\PDOStatement::class); + + $schema = new Schema(); + + $pdoSessionHandler = new PdoSessionHandler($pdo); + $pdoSessionHandler->configureSchema($schema, fn () => true); + + $this->assertTrue($schema->hasTable('sessions')); + $table = $schema->getTable('sessions'); + $this->assertSame('utf8mb4', $table->getOption('charset')); + $this->assertSame('utf8mb4_bin', $table->getOption('collate')); + } + public static function provideUrlDsnPairs() { yield ['mysql://localhost/test', 'mysql:host=localhost;dbname=test;'];