PrestaShop

PrestaShop Character Encoding Fix: Mastering Mojibake After CSV Imports with SQL

One of the most common headaches for PrestaShop merchants, especially those managing large product catalogs, is dealing with character encoding issues after importing data via CSV files. This often manifests as garbled or "mojibake" characters appearing in product descriptions, names, or other text fields. At Migrate My Shop, your PrestaShop Migration Hub, we frequently encounter and resolve these challenges. This guide, inspired by a real-world PrestaShop forum dilemma, offers a robust, database-level solution to tackle this problem head-on.

SQL query in phpMyAdmin showing REPLACE functions to fix PrestaShop character encoding issues
SQL query in phpMyAdmin showing REPLACE functions to fix PrestaShop character encoding issues

The Dreaded Mojibake: Garbled Characters Post-CSV Import

The problem is instantly recognizable: instead of seeing correctly accented words like "qualité" or "caractéristiques", your PrestaShop store displays bizarre sequences such as "qualité" and "caractéristiques". This phenomenon, known as "mojibake," occurs when text encoded in one character set (e.g., ISO-8859-1 or Windows-1252) is interpreted by a system expecting another (like UTF-8, which PrestaShop predominantly uses).

The forum thread, initiated by user JC_, perfectly illustrates this classic scenario. After a CSV import, their product descriptions were riddled with incorrect characters. The critical aspect of JC_'s predicament was the sheer scale – thousands, potentially tens of thousands, of product sheets were affected. This volume made manual correction or a simple re-import after re-encoding the CSV a daunting, if not impossible, task.

The example provided by JC_ was clear:

Batterie de qualité pour American DJ Z-WIF268. Respecte les caractéristiques

This should have read:

Batterie de qualité pour American DJ Z-WIF268. Respecte les caractéristiques

Initial Recommendations vs. Practical Challenges for Large Catalogs

The first reply from Eolia suggested the standard approach: "Encodez votre fichier en UTF-8 et ré-importez." While technically correct and often the first step in troubleshooting encoding issues, JC_ rightly pointed out the practical difficulty for their specific case. Re-importing tens of thousands of product sheets could lead to data loss or overwrites if not handled meticulously, and the process itself would be incredibly time-consuming, potentially causing significant downtime or errors in a live e-commerce environment.

This highlights a crucial point in e-commerce management: ideal solutions aren't always practical for large-scale operations. Merchants often need more direct, bulk-action methods that minimize risk and maximize efficiency.

The Community-Driven Solution: Direct SQL Correction

Recognizing the limitations of re-importing, JC_ explored a more direct route: correcting the data directly within the PrestaShop database. This approach leverages the power of SQL's REPLACE function to target and fix specific character patterns across multiple database entries simultaneously.

JC_'s initial discovery was a targeted SQL query:

UPDATE om4f_product_lang SET descripti (description_short, 'caractéristiques', 'caractéristiques') where description_short like '%caractéristiques%';

This query effectively replaced a specific garbled word with its correct version. While effective for a single word, Eolia quickly refined this approach, suggesting a more generalized solution to replace the problematic character sequences themselves, rather than entire words. This is far more efficient as it catches all occurrences of a specific encoding error, regardless of the word it appears in.

Eolia's refined suggestion:

UPDATE om4f_product_lang SET description = REPLACE (description, 'é', 'é'), descripti (description_short, 'é', 'é') ;

Implementing a Comprehensive SQL Fix for PrestaShop

To apply this solution comprehensively, you'll need to identify the common garbled patterns in your database and their correct UTF-8 equivalents. For French accents, these are some of the most frequent:

  • é becomes é
  • è becomes è
  • Ã becomes à
  • ç becomes ç
  • î becomes î
  • ï becomes ï
  • ô becomes ô
  • ù becomes ù
  • û becomes û
  • Ü becomes Ü
  • À becomes À
  • É becomes É
  • È becomes È
  • Â becomes Â
  • ä becomes ä
  • ö becomes ö
  • ü becomes ü
  • ß becomes ß
  • € becomes (for the Euro symbol)

PrestaShop stores product-related text in tables like _product_lang (where _ is your database prefix, commonly ps_ or a custom one like om4f_ from the forum thread). Key fields to target include name, description, and description_short. You might also need to check meta_title, meta_description, or even link_rewrite (though be cautious with link_rewrite as it affects URLs).

CRITICAL WARNING: Always, always, ALWAYS back up your PrestaShop database before running any direct SQL queries. A single mistake can lead to irreversible data loss.

Here's a comprehensive SQL query you can adapt. Remember to replace ps_ with your actual database prefix:

-- ALWAYS BACKUP YOUR DATABASE BEFORE RUNNING ANY SQL QUERIES!
-- This query targets common French character encoding issues in product names, descriptions, and short descriptions.
-- Replace 'ps_' with your actual PrestaShop database table prefix.

UPDATE ps_product_lang
SET
    name = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(name, 'é', 'é'), 'è', 'è'), 'à ', 'à'), 'ç', 'ç'), 'î', 'î'), 'ï', 'ï'), 'ô', 'ô'), 'ù', 'ù'), 'û', 'û'), 'Ü', 'Ü'), 'À', 'À'), 'É', 'É'), 'È', 'È'), 'Â', 'Â'), 'ä', 'ä'), 'ö', 'ö'), 'ü', 'ü'), 'ß', 'ß'), '€', '€'),
    description = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(description, 'é', 'é'), 'è', 'è'), 'à ', 'à'), 'ç', 'ç'), 'î', 'î'), 'ï', 'ï'), 'ô', 'ô'), 'ù', 'ù'), 'û', 'û'), 'Ü', 'Ü'), 'À', 'À'), 'É', 'É'), 'È', 'È'), 'Â', 'Â'), 'ä', 'ä'), 'ö', 'ö'), 'ü', 'ü'), 'ß', 'ß'), '€', '€'),
    descripti 'é', 'é'), 'è', 'è'), 'à ', 'à'), 'ç', 'ç'), 'î', 'î'), 'ï', 'ï'), 'ô', 'ô'), 'ù', 'ù'), 'û', 'û'), 'Ü', 'Ü'), 'À', 'À'), 'É', 'É'), 'È', 'È'), 'Â', 'Â'), 'ä', 'ä'), 'ö', 'ö'), 'ü', 'ü'), 'ß', 'ß'), '€', '€');

You can execute this query using tools like phpMyAdmin (available in most hosting control panels), Adminer, or directly via a MySQL client if you have command-line access. After execution, clear your PrestaShop cache to see the changes reflected on your storefront.

Preventative Measures: Avoiding Future Mojibake

While direct SQL fixes are powerful, prevention is always better. Here are key practices to avoid character encoding issues in your PrestaShop store:

  • Always Use UTF-8 for CSVs: When creating or saving CSV files, ensure they are encoded in UTF-8. Most modern spreadsheet software (Excel, LibreOffice Calc, Google Sheets) allows you to specify the encoding during the "Save As" or "Export" process.
  • Verify Export Settings: If you're exporting data from another system, confirm its export encoding is UTF-8.
  • Use a Robust Text Editor: Before importing, open your CSV file in a text editor like Notepad++ (Windows) or Sublime Text/VS Code (cross-platform). These editors can detect and convert file encodings, allowing you to confirm it's UTF-8 without BOM (Byte Order Mark) before import.
  • PrestaShop Import Settings: While PrestaShop generally expects UTF-8, always double-check the encoding option during the import process to ensure it matches your file.

Conclusion: Empowering Your PrestaShop Data Management

The challenge of character encoding, while frustrating, is a common hurdle in e-commerce, particularly during data migration or bulk updates. As demonstrated by the PrestaShop community, direct SQL manipulation offers a highly effective and efficient solution for large-scale corrections that manual methods or simple re-imports cannot match.

By understanding the root cause of mojibake and applying targeted SQL fixes, you can maintain a clean, professional-looking PrestaShop store, ensuring your product information is always displayed correctly. Remember the golden rule: backup before you update!

For complex PrestaShop migrations, data cleaning, or any e-commerce challenges, the experts at Migrate My Shop are here to help. We specialize in ensuring your data integrity and a smooth transition, every step of the way.

Share:

Start with the tools

Explore migration tools

See options, compare methods, and pick the path that fits your store.

Explore migration tools