Home >Backend Development >PHP Problem >How to deal with garbled Chinese characters in PHP+MYSQL

How to deal with garbled Chinese characters in PHP+MYSQL

coldplay.xixi
coldplay.xixiOriginal
2020-08-06 11:45:112199browse

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)].

How to deal with garbled Chinese characters in PHP+MYSQL

Solution to PHP MYSQL Chinese garbled code:

1. Set the encoding type to # when creating the table ##gb2312_chinese_ci.

2. Add a line to the database connection statement on the PHP page

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn