Home > Backend Development > PHP Problem > How to solve the problem of Chinese garbled characters in php sql

How to solve the problem of Chinese garbled characters in php sql

藏色散人
Release: 2023-03-04 22:50:02
Original
2861 people have browsed it

Solution to php sql Chinese garbled code: 1. Ensure that all pages and databases use the same encoding; 2. Set "mysql_query('set names utf8');"; 3. Add in the php code "charset=utf-8".

How to solve the problem of Chinese garbled characters in php sql

Recommendation: "PHP Video Tutorial"

1. First, make sure all pages and The databases all use the same encoding. It is strongly recommended to use utf-8;

2. When using mysql_query to query, whether it is writing data to mysql still extracts data from mysql, set
mysql_query('set names utf8'); Be careful not to write "utf8" as "utf-8", this is very important, otherwise it will The following embarrassing appearance will occur, and the Chinese characters will appear as a bunch of ??? numbers.


3. Add header("content-type: text/html; charset=utf-8 in the php code ");


## Note: PHP's header() function sends the original HTTP header to the client, which must be The header() function is called before the actual output is sent (i.e. written at the front).

Another thing to note is that content-type: text/html; charset=utf-8 are separated by semicolons instead of Comma , this little detail bugs me...

The above is the detailed content of How to solve the problem of Chinese garbled characters in php sql. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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