Asking for advice php+mysql garbled problem

Source: Internet
Author: User
The database can only be managed by phpMyAdmin because of the server provider. The current database is queried using the show variables statement 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 have written a test file mytest.php code as follows (file encoded as UTF-8):

 
  
 
  

The display is garbled.
If you modify the code as follows and change the encoding of the file to ANSI. It will display normally.

 
  

What is this cause of garbled characters? What do you do if you want to work around this problem?

Reply content:

The database can only be managed by phpMyAdmin because of the server provider. The current database is queried using the show variables statement 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 have written a test file mytest.php code as follows (file encoded as UTF-8):

 
  
 
  

The display is garbled.
If you modify the code as follows and change the encoding of the file to ANSI. It will display normally.

 
  

What is this cause of garbled characters? What do you do if you want to work around this problem?

mysql_query ("Set names UTF8");
Before all query statements are placed in the linked database
And check if all the files are UTF8 encoded.
Finally, the meta-information of HTML code is increased UTF8 processing should be resolved

Unify the code. MySQL full-use utf8,php file as long as the UTF8 is OK, do not set another encoding.

Workaround:

3. Modify My.ini, add default-character-set = UTF8 in [client], [mysqld], [MySQL], mysqld, basedir in [DataDir].
[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 ...

Add: This service provider is also sick enough, the database is UTF8, the connection is also UTF8, the results are returned with latin1 ... That's why you're out there. If you cannot change the server configuration, you should try to turn the results back into UTF8 with iconv.

Add a try to the HTML tag .

  • Related Article

    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.