UTF-8: showing correctly in database, however not in HTML despite utf-8 charset

前端 未结 2 1183
闹比i
闹比i 2020-12-10 05:53

I use MySQL 5.1 and loaded from a UTF-8 decoded txt-file about 2.7 mil lines into a table which itself is declared as utf8_unicode_ci and as well all char-field

相关标签:
2条回答
  • 2020-12-10 06:25

    Note: MySQL's utf8 charset is limited, it only supports Unicode characters in the BMP that take up no more than three bytes. You should be using utf8mb4 instead.

    • Make sure you send the SET NAMES utf8 SET NAMES utf8mb4 command to MySQL after connecting, before running any MySQL queries.
    • Make sure your page is actually rendered as utf-8 (if there's an HTTP header Content-Type: text/html;charset=iso-8859-1, browsers disagree about which should win).
    • Read this article: Handling Unicode Front To Back In A Web App (but remember to replace utf8 with utf8mb4 where MySQL is concerned).

    If phpMyAdmin displays your entered data as correct Unicode text, then my bet is that you are not doing SET NAMES utf8 after connecting.

    0 讨论(0)
  • 2020-12-10 06:36

    Try use such code after connecting to DataBase, but befor you recieve data

    $db->query('set character_set_client=utf8');
    $db->query('set character_set_connection=utf8');
    $db->query('set character_set_results=utf8');
    $db->query('set character_set_server=utf8');
    
    0 讨论(0)
提交回复
热议问题