Skip to content

Commit a093d87

Browse files
committed
Change default charset encoding to utf8mb4 for full UTF-8 support
1 parent fbce635 commit a093d87

File tree

3 files changed

+18
-22
lines changed

3 files changed

+18
-22
lines changed

README.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,10 @@ authentication. You can explicitly pass a custom timeout value in seconds
175175
$factory->createConnection('localhost?timeout=0.5');
176176
```
177177

178-
By default, the connection uses the `utf8` charset encoding. Note that
179-
MySQL's `utf8` encoding (also known as `utf8mb3`) predates what is now
180-
known as UTF-8 and for historical reasons doesn't support emojis and
181-
other characters. If you want full UTF-8 support, you can pass the
182-
charset encoding like this:
178+
By default, the connection provides full UTF-8 support (using the
179+
`utf8mb4` charset encoding). This should usually not be changed for most
180+
applications nowadays, but for legacy reasons you can change this to use
181+
a different ASCII-compatible charset encoding like this:
183182

184183
```php
185184
$factory->createConnection('localhost?charset=utf8mb4');
@@ -291,11 +290,10 @@ timeout) like this:
291290
$factory->createLazyConnection('localhost?idle=0.1');
292291
```
293292

294-
By default, the connection uses the `utf8` charset encoding. Note that
295-
MySQL's `utf8` encoding (also known as `utf8mb3`) predates what is now
296-
known as UTF-8 and for historical reasons doesn't support emojis and
297-
other characters. If you want full UTF-8 support, you can pass the
298-
charset encoding like this:
293+
By default, the connection provides full UTF-8 support (using the
294+
`utf8mb4` charset encoding). This should usually not be changed for most
295+
applications nowadays, but for legacy reasons you can change this to use
296+
a different ASCII-compatible charset encoding like this:
299297

300298
```php
301299
$factory->createLazyConnection('localhost?charset=utf8mb4');

src/Factory.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,10 @@ public function __construct(LoopInterface $loop = null, ConnectorInterface $conn
143143
* $factory->createConnection('localhost?timeout=0.5');
144144
* ```
145145
*
146-
* By default, the connection uses the `utf8` charset encoding. Note that
147-
* MySQL's `utf8` encoding (also known as `utf8mb3`) predates what is now
148-
* known as UTF-8 and for historical reasons doesn't support emojis and
149-
* other characters. If you want full UTF-8 support, you can pass the
150-
* charset encoding like this:
146+
* By default, the connection provides full UTF-8 support (using the
147+
* `utf8mb4` charset encoding). This should usually not be changed for most
148+
* applications nowadays, but for legacy reasons you can change this to use
149+
* a different ASCII-compatible charset encoding like this:
151150
*
152151
* ```php
153152
* $factory->createConnection('localhost?charset=utf8mb4');
@@ -183,7 +182,7 @@ public function createConnection(
183182
isset($parts['user']) ? rawurldecode($parts['user']) : 'root',
184183
isset($parts['pass']) ? rawurldecode($parts['pass']) : '',
185184
isset($parts['path']) ? rawurldecode(ltrim($parts['path'], '/')) : '',
186-
isset($args['charset']) ? $args['charset'] : 'utf8'
185+
isset($args['charset']) ? $args['charset'] : 'utf8mb4'
187186
);
188187
} catch (\InvalidArgumentException $e) {
189188
return \React\Promise\reject($e);
@@ -363,11 +362,10 @@ public function createConnection(
363362
* $factory->createLazyConnection('localhost?idle=0.1');
364363
* ```
365364
*
366-
* By default, the connection uses the `utf8` charset encoding. Note that
367-
* MySQL's `utf8` encoding (also known as `utf8mb3`) predates what is now
368-
* known as UTF-8 and for historical reasons doesn't support emojis and
369-
* other characters. If you want full UTF-8 support, you can pass the
370-
* charset encoding like this:
365+
* By default, the connection provides full UTF-8 support (using the
366+
* `utf8mb4` charset encoding). This should usually not be changed for most
367+
* applications nowadays, but for legacy reasons you can change this to use
368+
* a different ASCII-compatible charset encoding like this:
371369
*
372370
* ```php
373371
* $factory->createLazyConnection('localhost?charset=utf8mb4');

tests/ResultQueryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ public function testSelectCharsetDefaultsToUtf8()
361361
$connection->query('SELECT @@character_set_client')->then(function (QueryResult $command) {
362362
$this->assertCount(1, $command->resultRows);
363363
$this->assertCount(1, $command->resultRows[0]);
364-
$this->assertSame('utf8', reset($command->resultRows[0]));
364+
$this->assertSame('utf8mb4', reset($command->resultRows[0]));
365365
});
366366

367367
$connection->quit();

0 commit comments

Comments
 (0)