This article summarizes the common Chinese garbled problem in php+mysql storage data. Share to everyone for your reference, specific as follows:
Php+mysql The common reasons for Chinese garbled:
1. mysql database encoding is UTF8, and PHP page encoding format inconsistent, will cause MySQL in Chinese garbled.
2. Using MySQL to create a table, or select a field when the type set is not UTF8, and the page encoding is not UTF8, may also cause MySQL Chinese garbled.
3. The character set of the PHP page is inconsistent with the encoding of the database.
4. PHP connection MySQL database, operation is set the statement specified encoding and page encoding, PHP page encoding inconsistent.
5. User submitted HTML page encoding, and display data of the page coding inconsistent, will certainly cause the PHP page garbled.
Ways to solve Chinese garbled problems:
1. Web page encoding settings. Generally add properties to file headers
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
Guarantee that the webpage is "utf-8" encoded.
2. PHP code settings. Add the following code at the beginning of the PHP code:
Header ("Content-type:text/html;charset=utf-8");
The file encoding required to be saved is utf-8 (you can open the setting with EditPlus, as shown below), which ensures that the file is also utf-8 encoded.
3. The portion of the table in the database that stores Chinese in the field, to be set to the Utf8_general_ci type.
4.PHP when connecting to a database operation, the field type to set up the operation is UTF8, set the method as follows:
mysql_connect (' localhost ', ' user ', ' password ');
mysql_select_db (' db ');
mysql_query ("Set names UTF8"); * * Set the character set * * *
mysql_query (SQL statement to execute);
I hope this article will help you with the PHP program design.