How to solve php's problem of reading mysql Chinese garbled characters
Example: solve the problem of Chinese garbled characters in the following program.
-
-
-
-
- Data Testing
-
- $ Link = mysqli_connect ('localhost', 'root', '', 'Happy ');
- If (! $ Link ){
- Die ('could not connect to MySQL: '. mysql_error ());
- }
- // Solve Chinese garbled characters-set the default encoding
- $ Link-> query ("set names 'utf8 '");
-
- $ SQL = "select * from subway limit 5 ";
- $ Result = mysqli_query ($ link, $ SQL );
- While ($ row = mysqli_fetch_array ($ result )){
- Echo $ row ['id']. ":". $ row ['code']. ":". $ row ['name'];
- Echo"
";
- }
- Mysqli_close ($ link );
- ?>
-
-
Before garbled text: 1: subwayLine1 :?? 2: subwayLine1 :??? 3: subwayLine1 :??? 4: subwayLine1 :???? 5: subwayLine1 :???? Result 1: subwayLine1: Xinzhuang 2: subwayLine1: Outer Ring Road 3: subwayLine1: Lotus Road 4: subwayLine1: Jinjiang Park 5: subwayLine1: Shanghai South Railway Station This statement is mainly used: $ link-> query ("set names 'utf8'"); specifies the default character encoding. |