Today, when we were dealing with bugs, we found another strange problem. when we set mysql encoding to gbk, we found the created table, when the table structure, whether it is a field or table structure description, is Chinese, the table structure description is garbled. After troubleshooting that it was originally caused by character_set_clientbinary, after the mysql link is established, the encoding is set as follows:
The code is as follows:
Mysql_query ("SET character_set_connection = ". $ GLOBALS ['charset']. ", character_set_results = ". $ GLOBALS ['charset']. ", character_set_client = binary", $ this-> link );
However, the structure description of the created table is garbled:
The code is 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 (30) not null default ''comment' ������ ',
'Namespace' varchar (15) not null default 'global' comment' �� ���� ',
'Value' text comment' �� COMMENT ',
'Vtype' enum ('string', 'array', 'object') not null default 'string' comment' �������� ',
'Description' text comment' �� ',
Primary key ('namespace', 'name ')
) ENGINE = MyISAM default charset = gbk COMMENT = '�� n'
After investigation, we found that character_set_client = binary caused the following:
The code is as follows:
$ TargetDb-> query ("set names '{$ charset }'");
The code is 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 (30) not null default ''comment' configuration name ',
'Namespace' varchar (15) not null default 'global' comment' configure namespace ',
'Value' text comment' cache value ',
'Vtype' enum ('string', 'array', 'object') not null default 'string' COMMENT 'configuration value type ',
'Description' text comment' configuration introduction ',
Primary key ('namespace', 'name ')
) ENGINE = MyISAM default charset = gbk COMMENT = 'website configuration table'
However, if the character set I set is UTF8 and the table structure is utf8, even if the above character_set_client = binary is used, the table structure description is normal:
The code is 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 (30) not null default ''comment' configuration name ',
'Namespace' varchar (15) not null default 'global' comment' configure namespace ',
'Value' text comment' cache value ',
'Vtype' enum ('string', 'array', 'object') not null default 'string' COMMENT 'configuration value type ',
'Description' text comment' configuration introduction ',
Primary key ('namespace', 'name ')
) ENGINE = MyISAM default charset = utf8 COMMENT = 'website configuration table'
The strange thing is that garbled characters exist only in the description of the table structure, but the Chinese characters of the inserted data are still normal ~
I checked character_set_client = binary on the Internet and said "most of them are set to solve the garbled problem", but I don't know. this table structure description turns out to be garbled. What is the purpose of this? Why are the table structures different?