Issue with utf-8 encoding using PHP + MySQL

后端 未结 10 1469
谎友^
谎友^ 2020-12-16 12:41

I moved data from MySQL 4 (they were originally set to latin2 encoding) to MySQL 5 and set encoding to utf-8. It

相关标签:
10条回答
  • 2020-12-16 13:18

    try query

    SET NAMES utf8
    

    before any query in your application

    0 讨论(0)
  • 2020-12-16 13:20

    It doesn't seem like setting every SQL Database, Table, and Field to UTF-8 in MySQL and is good enough. Very annoying.

    Ended up forcing the issue to solve encoding problems:

    Had to use this Every place I open the database: $db->set_charset("utf8");

    And that worked. Finally.

    0 讨论(0)
  • 2020-12-16 13:27

    Here is a fix. Set the header to header ('Content-type: text/html; charset=utf-8'); Then print your content using utf8_decode($content). You must have the two to make it work.

    0 讨论(0)
  • 2020-12-16 13:29

    Try setting the MySQL connection to UTF-8:

    SET NAMES 'utf8'
    

    And send explicit UTF-8 headers, just in case your server has some other default settings:

    header('Content-type: text/html; charset=utf-8');
    
    0 讨论(0)
提交回复
热议问题