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

Collations are implicit #182

Closed
g105b opened this issue Jan 29, 2020 · 0 comments
Closed

Collations are implicit #182

g105b opened this issue Jan 29, 2020 · 0 comments
Assignees

Comments

@g105b
Copy link
Member

g105b commented Jan 29, 2020

When PDO binds data, it asks the schema for what type of data the binding should be done, so everything is done in a type-safe way. This is also the case for character sets and collations.

There are occasions when bindings are possible out-of-schema, such as when binding a value to a variable, e.g. select @example_variable := ?. Because this variable does not exist in the schema, PDO will infer the character set and collation from its connection information.

A bug arises when the connection is made in a different collation than the schema was created in. By default all schemas are created in utf8_general_ci, as this is loaded from the DefaultSettings object. However, when creating the PDO connection, the collation is never specified, so will default to whatever the OS deems as a correct default.

A recent update to MySQL/MariaDB has changed this default to move from utf8_general_ci to utf8_unicode_ci. This causes the issue in question when binding to out-of-schema values. When there is a mismatch of collations, MySQL throws an “Illegal mix of collations” error.

This can be solved by specifying the connection's collation using the MYSQL_ATTR_INIT_COMMAND attribute and setting to a value of SET SESSION collation_connection='$collation', where $collation can be loaded from the same consistent place that the migration script does.

@g105b g105b self-assigned this Jan 29, 2020
g105b added a commit that referenced this issue Jan 29, 2020
@g105b g105b closed this as completed in dc7c9cf Feb 6, 2020
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

No branches or pull requests

1 participant