Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change default charset encoding to utf8mb4 for full UTF-8 support #165

Merged
merged 1 commit into from
Oct 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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