Why is PHP processing database reading the encoding of & quot; Michael & quot; instead of Chinese characters? This post was last edited by gunzi318 from 2014-06-1719: 14: 13 & lt ;? Php & nbsp; $ con & nbsp; why does mysql_connect read "Michael" encoding instead of Chinese characters from the PHP processing database?
This post was last edited by gunzi318 at 19:14:13
$ Con = mysql_connect ("localhost", "root", "1234 ");
Mysql_select_db ("test", $ con );
Mysql_query ("set names utf8 ");
Mysql_query ("set character_set_client = utf8 ");
Mysql_query ("set character_set_results = utf8 ");
$ Q = mysql_query ("SELECT * FROM people ");
While ($ e = mysql_fetch_assoc ($ q )){
$ Output [] = $ e ;}
Print (json_encode ($ output ));
Mysql_close ();
?>
Output result:
[{"Id": "10", "name": "John", "sex": "1", "birthyear": "1979" },{ "id ": "11", "name:" \ u5f20 \ u4e09 "," sex ":" 1 "," birthyear ":" 1989 "}]
Why not James
------ Solution --------------------
Because you have json_encode, Chinese characters will not be combined.
Print (json_encode ($ output ));
Change
Print ($ output );
If you also want to see Chinese after json_encode, you can test my previous article: http://blog.csdn.net/fdipzone/article/details/28766357
------ Solution --------------------
Json_encode only accepts UTF-8 encoded data
During json encoding, json_encode converts multi-byte UTF-8 characters into double-byte unicode encoded entities.
In this way, bouquet will not cause data distortion due to encoding in any environment.
The json data format is mainly used for communication with js, while the browser converts any encoded data into its working character set unicode
Therefore, json_encode transcoding helps reduce the pressure on browsers.