Ask questions about php + mysql garbled characters

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.