php读取mysql中文乱码解决
<!DOCTYPE> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>数据测试</title> </head> <?php $link = mysqli_connect('localhost','root','','happy'); if (!$link) { die('Could not connect to MySQL: ' . mysql_error()); } // 解决中文乱码问题 $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 "<br>"; } mysqli_close($link); ?> </html>
乱码前是这样的:
1 : subwayLine1 : ?? 2 : subwayLine1 : ??? 3 : subwayLine1 : ??? 4 : subwayLine1 : ???? 5 : subwayLine1 : ????
解决中文乱码后结果是这样的:
1 : subwayLine1 : 莘庄 2 : subwayLine1 : 外环路 3 : subwayLine1 : 莲花路 4 : subwayLine1 : 锦江乐园 5 : subwayLine1 : 上海南站
相关推荐
opspider 2020-06-28
ZHANGRENXIANG00 2020-06-28
明瞳 2020-06-10
lanzhusiyu 2020-06-09
HSdiana 2020-06-03
PengQ 2020-05-26
lengyu0 2020-05-20
HSdiana 2020-05-11
haidaoxianzi 2020-04-18
PioneerFan 2020-04-09
HSdiana 2020-03-28
百年da孤独 2020-03-27
lwb 2020-03-26
haocxy 2020-03-08
spinachcqb 2020-03-06
柳永法的个人 2020-02-13
qsdnet我想学编程 2020-01-29
wwwxuewen 2020-01-19