Skip to content

Commit 02a9d7e

Browse files
authored
Merge pull request #7920 from kenjis/config-db-charset-utf8mb4
config: update default DB Charset to utf8mb4
2 parents 50b4c3d + 4e4f8bc commit 02a9d7e

12 files changed

Lines changed: 50 additions & 43 deletions

File tree

‎app/Config/Database.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class Database extends Config
3434
'DBPrefix' => '',
3535
'pConnect' => false,
3636
'DBDebug' => true,
37-
'charset' => 'utf8',
38-
'DBCollat' => 'utf8_general_ci',
37+
'charset' => 'utf8mb4',
38+
'DBCollat' => 'utf8mb4_general_ci',
3939
'swapPre' => '',
4040
'encrypt' => false,
4141
'compress' => false,
@@ -60,7 +60,7 @@ class Database extends Config
6060
'pConnect' => false,
6161
'DBDebug' => true,
6262
'charset' => 'utf8',
63-
'DBCollat' => 'utf8_general_ci',
63+
'DBCollat' => '',
6464
'swapPre' => '',
6565
'encrypt' => false,
6666
'compress' => false,

‎system/Database/BaseConnection.php‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,20 @@ abstract class BaseConnection implements ConnectionInterface
136136
/**
137137
* Character set
138138
*
139+
* This value must be updated by Config\Database if the driver use it.
140+
*
139141
* @var string
140142
*/
141-
protected $charset = 'utf8';
143+
protected $charset = 'utf8mb4';
142144

143145
/**
144146
* Collation
145147
*
148+
* This value must be updated by Config\Database if the driver use it.
149+
*
146150
* @var string
147151
*/
148-
protected $DBCollat = 'utf8_general_ci';
152+
protected $DBCollat = 'utf8mb4_general_ci';
149153

150154
/**
151155
* Swap Prefix

‎tests/_support/Config/Registrar.php‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class Registrar
3434
'DBPrefix' => 'db_',
3535
'pConnect' => false,
3636
'DBDebug' => true,
37-
'charset' => 'utf8',
38-
'DBCollat' => 'utf8_general_ci',
37+
'charset' => 'utf8mb4',
38+
'DBCollat' => 'utf8mb4_general_ci',
3939
'swapPre' => '',
4040
'encrypt' => false,
4141
'compress' => false,
@@ -54,7 +54,7 @@ class Registrar
5454
'pConnect' => false,
5555
'DBDebug' => true,
5656
'charset' => 'utf8',
57-
'DBCollat' => 'utf8_general_ci',
57+
'DBCollat' => '',
5858
'swapPre' => '',
5959
'encrypt' => false,
6060
'compress' => false,
@@ -73,7 +73,7 @@ class Registrar
7373
'pConnect' => false,
7474
'DBDebug' => true,
7575
'charset' => 'utf8',
76-
'DBCollat' => 'utf8_general_ci',
76+
'DBCollat' => '',
7777
'swapPre' => '',
7878
'encrypt' => false,
7979
'compress' => false,
@@ -93,7 +93,7 @@ class Registrar
9393
'pConnect' => false,
9494
'DBDebug' => true,
9595
'charset' => 'utf8',
96-
'DBCollat' => 'utf8_general_ci',
96+
'DBCollat' => '',
9797
'swapPre' => '',
9898
'encrypt' => false,
9999
'compress' => false,
@@ -112,7 +112,7 @@ class Registrar
112112
'pConnect' => false,
113113
'DBDebug' => true,
114114
'charset' => 'AL32UTF8',
115-
'DBCollat' => 'utf8_general_ci',
115+
'DBCollat' => '',
116116
'swapPre' => '',
117117
'encrypt' => false,
118118
'compress' => false,

‎tests/system/Database/BaseConnectionTest.php‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ final class BaseConnectionTest extends CIUnitTestCase
3333
'DBPrefix' => 'test_',
3434
'pConnect' => true,
3535
'DBDebug' => (ENVIRONMENT !== 'production'),
36-
'charset' => 'utf8',
37-
'DBCollat' => 'utf8_general_ci',
36+
'charset' => 'utf8mb4',
37+
'DBCollat' => 'utf8mb4_general_ci',
3838
'swapPre' => '',
3939
'encrypt' => false,
4040
'compress' => false,
@@ -51,8 +51,8 @@ final class BaseConnectionTest extends CIUnitTestCase
5151
'DBPrefix' => 'test_',
5252
'pConnect' => true,
5353
'DBDebug' => (ENVIRONMENT !== 'production'),
54-
'charset' => 'utf8',
55-
'DBCollat' => 'utf8_general_ci',
54+
'charset' => 'utf8mb4',
55+
'DBCollat' => 'utf8mb4_general_ci',
5656
'swapPre' => '',
5757
'encrypt' => false,
5858
'compress' => false,
@@ -71,8 +71,8 @@ public function testSavesConfigOptions(): void
7171
$this->assertSame('MockDriver', $db->DBDriver);
7272
$this->assertTrue($db->pConnect);
7373
$this->assertTrue($db->DBDebug);
74-
$this->assertSame('utf8', $db->charset);
75-
$this->assertSame('utf8_general_ci', $db->DBCollat);
74+
$this->assertSame('utf8mb4', $db->charset);
75+
$this->assertSame('utf8mb4_general_ci', $db->DBCollat);
7676
$this->assertSame('', $db->swapPre);
7777
$this->assertFalse($db->encrypt);
7878
$this->assertFalse($db->compress);
@@ -153,7 +153,7 @@ public function testMagicGet(): void
153153
{
154154
$db = new MockConnection($this->options);
155155

156-
$this->assertSame('utf8', $db->charset);
156+
$this->assertSame('utf8mb4', $db->charset);
157157
}
158158

159159
public function testMagicGetMissing(): void

‎tests/system/Database/ConfigTest.php‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ final class ConfigTest extends CIUnitTestCase
3333
'DBPrefix' => 'test_',
3434
'pConnect' => true,
3535
'DBDebug' => (ENVIRONMENT !== 'production'),
36-
'charset' => 'utf8',
37-
'DBCollat' => 'utf8_general_ci',
36+
'charset' => 'utf8mb4',
37+
'DBCollat' => 'utf8mb4_general_ci',
3838
'swapPre' => '',
3939
'encrypt' => false,
4040
'compress' => false,
@@ -52,8 +52,8 @@ final class ConfigTest extends CIUnitTestCase
5252
'DBPrefix' => 't_',
5353
'pConnect' => false,
5454
'DBDebug' => (ENVIRONMENT !== 'production'),
55-
'charset' => 'utf8',
56-
'DBCollat' => 'utf8_general_ci',
55+
'charset' => 'utf8mb4',
56+
'DBCollat' => 'utf8mb4_general_ci',
5757
'swapPre' => '',
5858
'encrypt' => false,
5959
'compress' => false,
@@ -71,8 +71,8 @@ final class ConfigTest extends CIUnitTestCase
7171
'DBPrefix' => 't_',
7272
'pConnect' => false,
7373
'DBDebug' => (ENVIRONMENT !== 'production'),
74-
'charset' => 'utf8',
75-
'DBCollat' => 'utf8_general_ci',
74+
'charset' => 'utf8mb4',
75+
'DBCollat' => 'utf8mb4_general_ci',
7676
'swapPre' => '',
7777
'encrypt' => false,
7878
'compress' => false,
@@ -90,8 +90,8 @@ final class ConfigTest extends CIUnitTestCase
9090
'DBPrefix' => 't_',
9191
'pConnect' => false,
9292
'DBDebug' => (ENVIRONMENT !== 'production'),
93-
'charset' => 'utf8',
94-
'DBCollat' => 'utf8_general_ci',
93+
'charset' => 'utf8mb4',
94+
'DBCollat' => 'utf8mb4_general_ci',
9595
'swapPre' => '',
9696
'encrypt' => false,
9797
'compress' => false,
@@ -157,8 +157,8 @@ public function testConnectionGroupWithDSNPostgre(): void
157157
$this->assertSame('Postgre', $this->getPrivateProperty($conn, 'DBDriver'));
158158
$this->assertSame('test_', $this->getPrivateProperty($conn, 'DBPrefix'));
159159
$this->assertFalse($this->getPrivateProperty($conn, 'pConnect'));
160-
$this->assertSame('utf8', $this->getPrivateProperty($conn, 'charset'));
161-
$this->assertSame('utf8_general_ci', $this->getPrivateProperty($conn, 'DBCollat'));
160+
$this->assertSame('utf8mb4', $this->getPrivateProperty($conn, 'charset'));
161+
$this->assertSame('utf8mb4_general_ci', $this->getPrivateProperty($conn, 'DBCollat'));
162162
$this->assertTrue($this->getPrivateProperty($conn, 'strictOn'));
163163
$this->assertSame([], $this->getPrivateProperty($conn, 'failover'));
164164
$this->assertSame('5', $this->getPrivateProperty($conn, 'connect_timeout'));
@@ -185,8 +185,8 @@ public function testConnectionGroupWithDSNPostgreNative(): void
185185
$this->assertSame('Postgre', $this->getPrivateProperty($conn, 'DBDriver'));
186186
$this->assertSame('t_', $this->getPrivateProperty($conn, 'DBPrefix'));
187187
$this->assertFalse($this->getPrivateProperty($conn, 'pConnect'));
188-
$this->assertSame('utf8', $this->getPrivateProperty($conn, 'charset'));
189-
$this->assertSame('utf8_general_ci', $this->getPrivateProperty($conn, 'DBCollat'));
188+
$this->assertSame('utf8mb4', $this->getPrivateProperty($conn, 'charset'));
189+
$this->assertSame('utf8mb4_general_ci', $this->getPrivateProperty($conn, 'DBCollat'));
190190
$this->assertTrue($this->getPrivateProperty($conn, 'strictOn'));
191191
$this->assertSame([], $this->getPrivateProperty($conn, 'failover'));
192192
}

‎user_guide_src/source/database/configuration/001.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class Database extends Config
1818
'DBPrefix' => '',
1919
'pConnect' => false,
2020
'DBDebug' => true,
21-
'charset' => 'utf8',
22-
'DBCollat' => 'utf8_general_ci',
21+
'charset' => 'utf8mb4',
22+
'DBCollat' => 'utf8mb4_general_ci',
2323
'swapPre' => '',
2424
'encrypt' => false,
2525
'compress' => false,

‎user_guide_src/source/database/configuration/004.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Database extends Config
1010

1111
// MySQLi
1212
public array $default = [
13-
'DSN' => 'MySQLi://username:password@hostname:3306/database?charset=utf8&DBCollat=utf8_general_ci',
13+
'DSN' => 'MySQLi://username:password@hostname:3306/database?charset=utf8mb4&DBCollat=utf8mb4_general_ci',
1414
// ...
1515
];
1616

‎user_guide_src/source/database/configuration/005.php‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class Database extends Config
2020
'DBPrefix' => '',
2121
'pConnect' => true,
2222
'DBDebug' => true,
23-
'charset' => 'utf8',
24-
'DBCollat' => 'utf8_general_ci',
23+
'charset' => 'utf8mb4',
24+
'DBCollat' => 'utf8mb4_general_ci',
2525
'swapPre' => '',
2626
'encrypt' => false,
2727
'compress' => false,
@@ -36,8 +36,8 @@ class Database extends Config
3636
'DBPrefix' => '',
3737
'pConnect' => true,
3838
'DBDebug' => true,
39-
'charset' => 'utf8',
40-
'DBCollat' => 'utf8_general_ci',
39+
'charset' => 'utf8mb4',
40+
'DBCollat' => 'utf8mb4_general_ci',
4141
'swapPre' => '',
4242
'encrypt' => false,
4343
'compress' => false,

‎user_guide_src/source/database/configuration/006.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class Database extends Config
1818
'DBPrefix' => '',
1919
'pConnect' => true,
2020
'DBDebug' => true,
21-
'charset' => 'utf8',
22-
'DBCollat' => 'utf8_general_ci',
21+
'charset' => 'utf8mb4',
22+
'DBCollat' => 'utf8mb4_general_ci',
2323
'swapPre' => '',
2424
'compress' => false,
2525
'encrypt' => false,

‎user_guide_src/source/database/connecting/006.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
'DBPrefix' => '',
1111
'pConnect' => false,
1212
'DBDebug' => true,
13-
'charset' => 'utf8',
14-
'DBCollat' => 'utf8_general_ci',
13+
'charset' => 'utf8mb4',
14+
'DBCollat' => 'utf8mb4_general_ci',
1515
'swapPre' => '',
1616
'encrypt' => false,
1717
'compress' => false,

0 commit comments

Comments
 (0)