Error in strings with UTF-8 character format encoding

Created on 24 February 2023, almost 2 years ago
Updated 6 April 2023, over 1 year ago

Problem/Motivation

When importing a csv containing strings in UTF-8 character encoding format an error occurs when launching a query to the database.

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[HY000]: General error: 1267 Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8mb4_general_ci,COERCIBLE) for operation '=': SELECT n.tid FROM {taxonomy_term_field_data} n WHERE n.name = :uid AND n.vid = :vid; Array ( [:uid] => Alcal� de Henares [:vid] => municipios_madrid ) en Drupal\taxonomy_import\Form\create_taxonomy() (linea 148 de /var/www/html/web/modules/contrib/taxonomy_import/src/Form/ImportForm.php).

Steps to reproduce

In a database with collation 'utf8_unicode_ci' (use the query "SELECT @@character_set_database, @@collation_database;" to check), import a csv file containing strings with UTF-8 format (such as 'á, é, í, ó, ú, ñ...). When importing the .csv, you will reproduce the exception.

Proposed resolution

Encode the string "$data[0]" to UTF-8 before launching the query to the database.

Remaining tasks

Working on a patch.

User interface changes

None.

API changes

None.

Data model changes

None.

🐛 Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

🇪🇸Spain juandels3 Seville

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024