The server provider can only use phpMyadmin to manage databases. The information of the current database obtained by using the showvariables statement is as follows: character_set_clientlatin1character_set_connectionutf8character_set_databaseutf8char .. the server provider can only use phpMyadmin to manage the database. The information of the current database obtained by using the show variables statement is as follows:
Character_set_clientlatin1
Character_set_connectionutf8
Character_set_databaseutf8
Character_set_resultslatin1
Character_set_serverlatin1
Character_set_systemutf8
Collation_connectionutf8_unicode_ci
Collation_databaseutf8_unicode_ci
Collation_serverlatin1_swedish_ci
I wrote a test file mytest. php code as follows (the file code is UTF-8 ):
Garbled characters are displayed.
If you modify the code as follows and change the file encoding to ANSI. It will be displayed normally
What causes garbled characters? How can I solve this problem?
Reply content:
The server provider can only use phpMyadmin to manage databases. The information of the current database obtained by using the show variables statement is as follows:
Character_set_clientlatin1
Character_set_connectionutf8
Character_set_databaseutf8
Character_set_resultslatin1
Character_set_serverlatin1
Character_set_systemutf8
Collation_connectionutf8_unicode_ci
Collation_databaseutf8_unicode_ci
Collation_serverlatin1_swedish_ci
I wrote a test file mytest. php code as follows (the file code is UTF-8 ):
Garbled characters are displayed.
If you modify the code as follows and change the file encoding to ANSI. It will be displayed normally
What causes garbled characters? How can I solve this problem?
Mysql_query ("set names utf8 ");
Before all query statements after the database connection
Then, check whether all files are UTF-8 encoded.
At last, the utf8 processing should be added to the meta information of the html code.
Unified encoding. Mysql uses utf8, and PHP files only need utf8. Do not set the encoding.
Solution:
3. modify my. ini, add default-character-set = utf8 after [client], [mysqld], and [mysql], and add basedir and datadir under [mysqld.
[Client]
Default-character-set = utf8
[Mysqld]
Default-character-set = utf8
Default-collation = utf8_bin
Init_connect = 'set NAMES utf8'
Basedir = D: \ mysql \
Datadir = D: \ mysql \ data \
[Mysql]
Default-character-set = utf8
Reference: http://hi.baidu.com/hiran/blog/item/5...
Supplement: this service provider is also abnormal. The database is utf8 and the connection is utf8. The returned result is latin1... This is the reason for you. If you cannot change the server configuration, use iconv to convert the returned results to utf8.
HtmlAdd Try.