For the mysql character set character_set_client=binary. In the case of gbk the table description will be scrambled
- 2020-05-27 04:31:01
- OfStack
After the mysql link is established, the encoding is set as follows:
However, the resulting table structure description turned out to be garbled:
After investigation, it turned out that character_set_client=binary was to blame:
However, if the character set I set is UTF8 and the table structure is utf8, then even if the character_set_client=binary above is used, the table structure description is normal:
And strange thing, garbled code only exists in the description of the table structure, for the inserted data Chinese is still normal ~
I checked character_set_client=binary on the Internet and said that "most of them are set to solve the problem of scrambled codes", but I do not know that this description of the table structure turned out to be scrambled codes. What exactly does this do? Why don't you do the same with the table structure?
mysql_query("SET character_set_connection=" . $GLOBALS['charset'] . ",character_set_results=" . $GLOBALS['charset'] . ",character_set_client=binary", $this->link);
However, the resulting table structure description turned out to be garbled:
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 '����ֵ',
`vtype` enum('string','array','object') NOT NULL DEFAULT 'string' COMMENT '����ֵ����',
`description` text COMMENT '���ý���',
PRIMARY KEY (`namespace`,`name`)
) ENGINE=MyISAM DEFAULT CHARSET=gbk COMMENT='��վ���ñ�'
After investigation, it turned out that character_set_client=binary was to blame:
$targetDb->query("SET NAMES '{$charset}'");
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 ' The name of the configuration ',
`namespace` varchar(15) NOT NULL DEFAULT 'global' COMMENT ' Configure the namespace ',
`value` text COMMENT ' The cache value ',
`vtype` enum('string','array','object') NOT NULL DEFAULT 'string' COMMENT ' Configuration value type ',
`description` text COMMENT ' Configuration is introduced ',
PRIMARY KEY (`namespace`,`name`)
) ENGINE=MyISAM DEFAULT CHARSET=gbk COMMENT=' Site profile '
However, if the character set I set is UTF8 and the table structure is utf8, then even if the character_set_client=binary above is used, the table structure description is normal:
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 ' The name of the configuration ',
`namespace` varchar(15) NOT NULL DEFAULT 'global' COMMENT ' Configure the namespace ',
`value` text COMMENT ' The cache value ',
`vtype` enum('string','array','object') NOT NULL DEFAULT 'string' COMMENT ' Configuration value type ',
`description` text COMMENT ' Configuration is introduced ',
PRIMARY KEY (`namespace`,`name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT=' Site profile '
And strange thing, garbled code only exists in the description of the table structure, for the inserted data Chinese is still normal ~
I checked character_set_client=binary on the Internet and said that "most of them are set to solve the problem of scrambled codes", but I do not know that this description of the table structure turned out to be scrambled codes. What exactly does this do? Why don't you do the same with the table structure?