The problem of using UTF-8 encoding for MYSQL database
1. Use phpmyadmin to create the database and data table
Create the database When creating a data table, please set "Organization" to: "utf8_general_ci" or execute the statement:
1 |
|
When creating a data table: If the field stores Chinese, you need to set "Organization" to: " utf8_general_ci",
If this field stores English or numbers, the default is fine.
Corresponding SQL statement, for example:
1 2 3 4 5 |
|
2. Use PHP to read and write the database
After connecting to the database:
1 |
|
Add two lines:
1 2 3 4 |
|
Then you can read and write the MYSQL database normally.
The environment made using appserv-win32-2.5.10 uses the default utf8 encoding when installing this package.
When writing the database connection file, write:
1 2 3 |
|
Then when making the page, pay attention to this sentence:
1 |
|
In this way, regardless of the Chinese input into the database, or the page display, It's all normal.
In the DW CS4 version, the utf8 page is also generated by default.
Similarly, if you first write the database connection file as: mysql_query("SET NAMES 'GBK'");
Then the page will also change accordingly:
1 |
|
For more PHP-related knowledge, please visit PHP中文网!
The above is the detailed content of Database php Chinese characters garbled. For more information, please follow other related articles on the PHP Chinese website!