Whether it is ASP or PHP programming language, or even other web languages, the basic application is nothing more than the requirements of database adding, reading, editing, deleting, and so on. No matter how complex the functional projects are, they are all carried out around these. In the input MySQL database when the Chinese data submitted garbled problem, this problem for beginners learning PHP must have encountered.
In fact, the problem is relatively simple, it must be caused by the wrong coding. For example, page coding, database field coding, and database link coding. Here, we all adopts UTF-8 coding. We need to find these problems and solve the problem of garbled code.
First, page coding
We need to keep UTF-8 coding in web pages.
Second, the coding problem when creating the database
In the article “common commands and data type settings for creating MySQL database and data table with PHP”, we uses the method of SQL direct import. When we add database fields, if we need to keep all UTF-8 codes, we need to keep utf8 of database fields in the last “charset = utf8”.
Third, the coding of database links
In the database link file, we need to set:
mysql_ query(“set names ‘utf8′”);
The same is the utf8 encoding setting.
In this way, through the unified coding of three places, we can definitely solve the problem of garbled code after submitting data.