The ultimate solution to garbled data display
The php connection to mysql is garbled during the development process. This is a problem often encountered by novices in development. Based on the actual problems encountered by everyone, the problem of garbled characters has been summarized into 9 key points to completely solve the problem of garbled characters after connection.
The core idea to solve the problem of garbled characters is: multiple different file systems must have unified encoding.
These 9 key points are:
1. html encoding is consistent with MySQL encoding
2. PHP encoding is consistent with MySQL encoding
3. If If there is a header to send the character set, please use the same character set as the database. The character encoding of the database must be consistent
5. The character set of the database must be unified
6. The character set of the table must be unified
7. The character set of the columns must be unified (table If set, the column will be written to the table by default)
8. The character set for connection and verification must be unified
9. The character set of the result set must be unified
1. File encodingEncoding of html and PHP files, in the example: use notepad++ to demonstrate. Set both PHP and html to this character set.
Must be set to utf-8 without BOM format.
二, Header head encoding
If there is a header head in the php, it must be UTF-8 header('content-type:text/html;charset=utf-8');3. Web page header file encoding
If the html file encoding is utf-8, it must also be set to one setting<meta http-equiv="Content-Type" content="text/html; charset=utf- 8” />4. Coding to create database
## 6. Connection, result, calibration Verify character set settings
Use mysqli_set_charset('utf8') to set the character set for MySQL connection, result and verification.
Note: The character set declaration of the database is slightly different from that in the file. UTF8 is for the MySQL database, and UTF-8 is used in files.