Skip to content

Commit

Permalink
Merge pull request #165 from clue-labs/utf8mb4
Browse files Browse the repository at this point in the history
Change default charset encoding to `utf8mb4` for full UTF-8 support
  • Loading branch information
WyriHaximus authored Oct 29, 2022
2 parents fbce635 + a093d87 commit 789124f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,10 @@ authentication. You can explicitly pass a custom timeout value in seconds
$factory->createConnection('localhost?timeout=0.5');
```

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

```php
$factory->createConnection('localhost?charset=utf8mb4');
Expand Down Expand Up @@ -291,11 +290,10 @@ timeout) like this:
$factory->createLazyConnection('localhost?idle=0.1');
```

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

```php
$factory->createLazyConnection('localhost?charset=utf8mb4');
Expand Down
20 changes: 9 additions & 11 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,10 @@ public function __construct(LoopInterface $loop = null, ConnectorInterface $conn
* $factory->createConnection('localhost?timeout=0.5');
* ```
*
* By default, the connection uses the `utf8` charset encoding. Note that
* MySQL's `utf8` encoding (also known as `utf8mb3`) predates what is now
* known as UTF-8 and for historical reasons doesn't support emojis and
* other characters. If you want full UTF-8 support, you can pass the
* charset encoding like this:
* By default, the connection provides full UTF-8 support (using the
* `utf8mb4` charset encoding). This should usually not be changed for most
* applications nowadays, but for legacy reasons you can change this to use
* a different ASCII-compatible charset encoding like this:
*
* ```php
* $factory->createConnection('localhost?charset=utf8mb4');
Expand Down Expand Up @@ -183,7 +182,7 @@ public function createConnection(
isset($parts['user']) ? rawurldecode($parts['user']) : 'root',
isset($parts['pass']) ? rawurldecode($parts['pass']) : '',
isset($parts['path']) ? rawurldecode(ltrim($parts['path'], '/')) : '',
isset($args['charset']) ? $args['charset'] : 'utf8'
isset($args['charset']) ? $args['charset'] : 'utf8mb4'
);
} catch (\InvalidArgumentException $e) {
return \React\Promise\reject($e);
Expand Down Expand Up @@ -363,11 +362,10 @@ public function createConnection(
* $factory->createLazyConnection('localhost?idle=0.1');
* ```
*
* By default, the connection uses the `utf8` charset encoding. Note that
* MySQL's `utf8` encoding (also known as `utf8mb3`) predates what is now
* known as UTF-8 and for historical reasons doesn't support emojis and
* other characters. If you want full UTF-8 support, you can pass the
* charset encoding like this:
* By default, the connection provides full UTF-8 support (using the
* `utf8mb4` charset encoding). This should usually not be changed for most
* applications nowadays, but for legacy reasons you can change this to use
* a different ASCII-compatible charset encoding like this:
*
* ```php
* $factory->createLazyConnection('localhost?charset=utf8mb4');
Expand Down
2 changes: 1 addition & 1 deletion tests/ResultQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public function testSelectCharsetDefaultsToUtf8()
$connection->query('SELECT @@character_set_client')->then(function (QueryResult $command) {
$this->assertCount(1, $command->resultRows);
$this->assertCount(1, $command->resultRows[0]);
$this->assertSame('utf8', reset($command->resultRows[0]));
$this->assertSame('utf8mb4', reset($command->resultRows[0]));
});

$connection->quit();
Expand Down

0 comments on commit 789124f

Please sign in to comment.