How does PHP read data from MySQL and output garbled characters?

Source: Internet
Author: User
PHP read data from MySQL output garbled MySQL: PHP file: & lt; html & gt; & lt; head & gt; & lt; meta & nbsp; charsetutf-8 & nbsp; & gt; & lt ;? Phpheader (Content-Type: & nbsp; texthtml; & nbsp; charsetutf-8); $ index & nbsp; PHP read data output garbled from MySQL
MySQL:



The PHP file is as follows:



Header ("Content-Type: text/html; charset = utf-8 ");
$ Index = 0;
$ Con = mysql_connect ("localhost", "root ","");
If (! $ Con)
{
Die ('could not connect: '. mysql_error ());
}
Mysql_select_db ("test", $ con );

Mysql_query ("set names 'utf8 '");
Mysql_query ("set character_set_client = utf8 ");
Mysql_query ("set character_set_results = utf8 ");

$ Result = mysql_query ("SELECT * FROM test_list
Limit 0, 4 ");

While ($ row = mysql_fetch_array ($ result ))
{
$ Load_crouse_array [$ index] = array (
'Subject _ id' => $ row ['subject _ id'],
'Subject _ title' => $ row ['subject _ title'],
'Subject _ url' => $ row ['subject _ url'],
'Subject _ belong '=> $ row ['subject _ belong'],
'Creat _ time' => $ row ['creat _ time']
);
$ Index ++;
}
Mysql_query ("insert into 'test '. 'test _ list' ('subject _ id', 'subject _ title', 'subject _ url', 'subject _ belong ', 'creat _ time ') VALUES ('20140901', 'Test text', 'Test _ url', 'Excel _ crous', '2017-08-10 ');");
Echo json_encode ($ load_crouse_array );
Echo "test Chinese ";
?>



Final output result:

At the same time, the inserted records are displayed as ??? in the Chinese part of the database ????.
This problem occurs when I use Eclipse programming and then directly use the text editing software Notepad ++. The environment is Windows 7, XMAPP, and chrome browser is used.

------ Solution --------------------
This is not garbled. this is encrypted in json format. if you want to view it, decrypt it when outputting it.
------ Solution --------------------
The data processed by your $ load_crouse_array array after json_encode is not garbled, but unicode processing of Chinese characters.
Output print_r ($ load_crouse_array); you can check whether the code is garbled.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.