Home >Backend Development >PHP Problem >How to deal with garbled Chinese characters in PHP+MYSQL
PHP MYSQL Chinese garbled solution: first set the encoding type to [gb2312_chinese_ci] when creating the table; then add relevant statements to the database connection statement on the PHP page, the code is [mysql_query("SET NAMES'gb2312 '",$link)].
Solution to PHP MYSQL Chinese garbled code:
1. Set the encoding type to # when creating the table ##gb2312_chinese_ci.
mysql_query("SET NAMES 'gb2312'",$link); For example
$db_host="localhost"; $db_user="root"; $db_password="password"; $db_name="test"; $link=mysql_connect($db_host,$db_user,$db_password); mysql_query("SET NAMES 'gb2312'",$link); $db=mysql_select_db($db_name,$link); $query="select * from user"; $result=mysql_query($query);Add this line to both the writing page and the reading page. In this way, the Chinese in MYSQL can be displayed normally.
Related learning recommendations:php programming (video)
The above is the detailed content of How to deal with garbled Chinese characters in PHP+MYSQL. For more information, please follow other related articles on the PHP Chinese website!