php mysql query encoding problem

后端 未结 2 614
慢半拍i
慢半拍i 2021-01-16 20:05

I have a page with utf-8 encodin. Mysql is set to utf8_general_ci. Here is the query:

 mysql_query(\"SET CHARACTER SET utf8_general_ci\");

               $         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-16 20:26

    What I tend to find solves things a lot is;

    mysql_query("SET NAMES 'utf8'");
    

    Before any queries are performed.

    The documentation recommends that you use mysql_set_charset but I often see that function missing.

    if( function_exists('mysql_set_charset') ){
        mysql_set_charset('utf8', $db_con);
    }else{
        mysql_query("SET NAMES 'utf8'", $db_con);
    }
    

提交回复
热议问题