How to deal with garbled Chinese characters in PHP+MYSQL

coldplay.xixi
Release: 2023-03-03 21:58:02
Original
2169 people have browsed it

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);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!