Unicode problems with MySQL

  • | 1735 points

    I'm struggling to find the right way to echo MySQL records in the right language.

    MySQL data shows:
    first_name = "Gérard"

    Echo on screen shows G�rard

    When debugging it shows also G�rard for the record field although I use latin1_general_cs in MySQL Collation.

    Does PHP change the character set? How to deal with this problem? Thanks for your help

  • | 16270 points

    @DickVG Unicode in MySQL, PHP and HTML can be a bind!

    There is good information on PHP the right way.

    I had problems a few months ago on a side project, after attending a meetup PHP Hampshire May 2021- How to tame a UNICORN_EMOJI, unfortunately, I can't see they recorded it. I did manage to fix my side project PHP AJAX CRUD using jQuery UI Demo maybe it will give you some more tips.

    To answer your question utf8mb4_unicode_ci is one of the latest Unicode standards for MySQL. This is not the only problem, headers in html must be correctly set <meta charset="utf-8"> and PHP needs to handle any strings, normally using mb* functions.

  • | 16270 points

  • | 1735 points

    You give me plenty of good information and I really thank you.

    I added the meta charset but no change.

    In MySQL the record show:


    What puzzles me is that when debugging, the record changes the characters.

    I presume I need to figure out why PHP fetches other characters while the collation is set to the latest Unicode standard.


  • | 1735 points

    I found the error!

    When executing the SQL in MySQL SHOW VARIABLES LIKE 'character_set%'; the variable character_set_server was set to Latin and all other variables were set to utf8mb4.

    So I needed to change the wrong variable.

    This can be done by adding the line character-set-server=utf8mb4 in my.ini and restart MySQL.

    Thanks again for your help @Pen-y-Fan

Log in to reply

Looks like your connection to Laragon was lost, please wait while we try to reconnect.