Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 theDefaultSettings
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
toutf8_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 ofSET SESSION collation_connection='$collation'
, where$collation
can be loaded from the same consistent place that the migration script does.