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".
Recommendation: "PHP Video Tutorial"
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.
## 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!