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
Conversation
@@ -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'; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"
}
This PR should also remove the code introduced by #1070. |
I still think we should just revert #1070 as this is no longer a problem in newer mysql versions. |
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. Maintaining this list in the bundle didn't look like a good idea to me. |
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. |
Agree with @nicolas-grekas here. Closing in favour of the other solution. |
Thanks for giving it a try @rosier! |
I like to purpose an alternative for #1070 and fix of #1087