Mysql database garbled saving Vietnamese garbled solution bitsCN.com
I tested it myself. many characters are changed '? '.
The utf8 character set is used for database connection:
Define ("MYSQL_ENCODE", "UTF8 ");
Mysql_query ('set names'. MYSQL_ENCODE, $ conn) or die ('character SET setting error'. mysql_error ());
It took more than half an hour.
The data in the insert statement is still garbled. I suddenly wondered if the field cannot store these Vietnamese files.
Let me take a look at the Database character set. the default character set is gbk. this is no problem with Chinese. when I encounter Vietnamese, it will be garbled.
Therefore, I changed the character set that may be used in Vietnamese fields to utf8, and the proofreading was changed to utf8_unicode_ci. (Here, you must modify a field to modify the character set of the entire table. The field still retains the original character set.) The problem is solved.
My database is php_college_web
Table: city_article
Fields used in Vietnamese: title and content
Execute the following SQL statement:
Alter table city_article CHANGE title VARCHAR (100) character set utf8 COLLATE utf8_unicode_ci
Alter table city_article CHANGE content text character set utf8 COLLATE utf8_unicode_ci
BitsCN.com