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?