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

Default to charset utf8mb4 for mysql and utf8 otherwise #1098

Closed
wants to merge 1 commit into from
Closed

Default to charset utf8mb4 for mysql and utf8 otherwise #1098

wants to merge 1 commit into from

Conversation

rosier
Copy link
Contributor

@rosier rosier commented Dec 17, 2019

I like to purpose an alternative for #1070 and fix of #1087

@@ -199,6 +200,14 @@ protected function getConnectionOptions($connection)
{
$options = $connection;

if (! isset($options['charset'])) {
if (isset($options['url'])) {
$options['charset'] = strpos($options['url'], 'mysql') === 0 ? 'utf8mb4' : 'utf8';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the scheme might also be pdo_mysql or mysqli as that's the name of the DBAL drivers, which are also supported as schemes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scheme mysqli also starts with mysql, so that should be fine.

I didn't account for pdo_mysql, I will look into that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think pdo_mysql can be use as a scheme, parse_url doesn't work with it. So that leaves just mysql, mysql2 and mysqli as a scheme.

$url = 'pdo_mysql://dbuser:dbpassword@127.0.0.1:3306/dbname?charset=utf8';
var_dump(parse_url($url));

array(2) {
  ["path"]=>  string(51) "pdo_mysql://dbuser:dbpassword@127.0.0.1:3306/dbname"
  ["query"]=>  string(12) "charset=utf8"
}

@stof
Copy link
Member

stof commented Dec 17, 2019

This PR should also remove the code introduced by #1070.

@ostrolucky
Copy link
Member

I still think we should just revert #1070 as this is no longer a problem in newer mysql versions.

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Dec 17, 2019

I did not implement the charset defaults this way because it harcodes the list and is thus impermeable to future prefixes that DBAL might handle.
The current list is way longer than what is proposed here, see:
https://github.com/doctrine/dbal/blob/f6312cb97c50eaa35999dc73894bd3fd23d7f60b/lib/Doctrine/DBAL/DriverManager.php#L50-L77

Maintaining this list in the bundle didn't look like a good idea to me.

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Dec 17, 2019

OH, last but not least, this doesn't work with database DSN. That's the definitive decider that made me go for the runtime logic. This approach just cannot work.

@alcaeus
Copy link
Member

alcaeus commented Dec 17, 2019

Agree with @nicolas-grekas here. Closing in favour of the other solution.

@alcaeus alcaeus closed this Dec 17, 2019
@nicolas-grekas
Copy link
Member

Thanks for giving it a try @rosier!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants