Issue with utf-8 encoding using PHP + MySQL

后端 未结 10 1526
谎友^
谎友^ 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:13

    On my server, adding these to my php file had no effect:

    ini_set('default_charset','utf-8');
    mysql_set_charset('utf8');
    header('Content-type: text/html; charset=utf-8');
    

    But everything worked perfectly once I added this to the top of my php file:

    $mysqli->query("SET NAMES 'utf8'");
    

    Note: I am using encoding utf8_general_ci in my database, but utf8_unicode_ci works the same for me.

    Hope that helps.

提交回复
热议问题