You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.The text was updated successfully, but these errors were encountered: