About the MySQL character set character_set_client=binary in GBK case will appear table description is garbled situation _php skills

Source: Internet
Author: User
After the MySQL link is established, set the encoding as follows:
Copy Code code as follows:

mysql_query ("SET character_set_connection=". $GLOBALS [' CharSet ']. ", character_set_results=." $GLOBALS [' CharSet ']. ", Character_set_client=binary", $this->link);

However, the established table structure description is garbled:
Copy Code code as follows:

Mysql> Show CREATE TABLE Nw_admin_config\g
1. Row ***************************
Table:nw_admin_config
Create table:create Table ' Nw_admin_config ' (
' Name ' varchar ' not NULL DEFAULT ' COMMENT ',
' namespace ' varchar not NULL DEFAULT ' global ' COMMENT ' Ռ ',
' Value ' text COMMENT ' ֵ ',
' VType ' enum (' string ', ' array ', ' object ') not NULL DEFAULT ' string ' COMMENT ' ֵ ',
' Description ' text COMMENT ' Ý ',
PRIMARY KEY (' namespace ', ' name ')
) Engine=myisam DEFAULT charset=gbk comment= ' Վñ '

After the investigation, found unexpectedly is character_set_client=binary caused the disaster:

Copy Code code as follows:
$targetDb->query ("SET NAMES ' {$charset} '");


Copy Code code as follows:

Mysql> Show CREATE TABLE Nw_admin_config\g
1. Row ***************************
Table:nw_admin_config
Create table:create Table ' Nw_admin_config ' (
' Name ' varchar ' not NULL DEFAULT ' COMMENT ' Configuration name ',
' namespace ' varchar not NULL DEFAULT ' global ' COMMENT ' config namespace ',
' Value ' text COMMENT ' cached values ',
' VType ' enum (' string ', ' array ', ' object ') not NULL DEFAULT ' string ' COMMENT ' config value type ',
' Description ' text COMMENT ' configuration introduction ',
PRIMARY KEY (' namespace ', ' name ')
) Engine=myisam DEFAULT charset=gbk comment= ' site Configuration table '

However, if I set the character set to be UTF8 and the table structure is UTF8, the table structure is described as normal even if the character_set_client=binary above is used:
Copy Code code as follows:

Mysql> Show CREATE TABLE Nw_admin_config\g
1. Row ***************************
Table:nw_admin_config
Create table:create Table ' Nw_admin_config ' (
' Name ' varchar ' not NULL DEFAULT ' COMMENT ' Configuration name ',
' namespace ' varchar not NULL DEFAULT ' global ' COMMENT ' config namespace ',
' Value ' text COMMENT ' cached values ',
' VType ' enum (' string ', ' array ', ' object ') not NULL DEFAULT ' string ' COMMENT ' config value type ',
' Description ' text COMMENT ' configuration introduction ',
PRIMARY KEY (' namespace ', ' name ')
) Engine=myisam DEFAULT Charset=utf8 comment= ' site Configuration table '

And strange things, garbled situation only in the table structure in the description only exist, for the inserted data Chinese is still normal ~

Online Check the character_set_client=binary are said to be "most of the problem to solve the garbled set", but I do not know, this table structure description unexpectedly instead of garbled. What is the role of this? Why is it different when the table is structured?

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.