In the past two days, we have introduced the addition and deletion of simple message Books. when we use databases, we often encounter garbled characters, and encoding problems often plague us. So how can we solve this problem for new users? The following are some notes
In the past two days, we have introduced the addition and deletion of simple message Books. when we use databases, we often encounter garbled characters, and encoding problems often plague us. So how can we solve this problem for new users? The following are some points worth attention.
First, unify the encoding of PHP, HTML files, and databases. for example, if GBK is used, set it on the corresponding page:
1. HTML page encoding settings:
2. php file encoding settings: header ('content-Type: text/html; charset = gbk ')
3. database encoding settings: Select gbk_chinese_ci when creating a database.
4, HTML, PHP file class type stored as ANSI, if the unified use of UTF-8 encoding, then the file type is saved as a UTF-8, be sure not to BOM header
Pay attention to the following steps when using the database:
1. first establish database connection mysql_connect ('localhost', 'root', 'root ')
2. select the database mysql_select_db ('database _ name ')
3. write an SQL statement: $ SQL = ""; (add, delete, modify, query, or CURD)
4. execute the SQL statement $ res = mysql_query ($ SQL)
5. obtain the result mysql_fetch_assoc ($ res)
Note: mysql_query () executes the SQL statement, and mysql_fetch_assoc () executes the data of the resource type returned by mysql_query.