Home  >  Article  >  Backend Development  >  Regarding the mysql character set, character_set_client=binary is set. In the case of gbk, the table description will be garbled_PHP tutorial

Regarding the mysql character set, character_set_client=binary is set. In the case of gbk, the table description will be garbled_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:13:41846browse

After the mysql link is established, set the encoding as follows:

Copy code 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, it is created The table structure description is garbled:
Copy code The code is as follows:

mysql> show create table nw_admin_configG
* *************************** 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 was found that character_set_client=binary was to blame:

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


Copy code The code is as follows:

mysql> show create table nw_admin_configG
**************************** 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 'Configuration 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 also utf8, then even The above character_set_client=binary is used, and the description of the table structure is normal:
Copy code The code is as follows:

mysql> show create table nw_admin_configG
****************************** 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 'Configuration 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'

And the strange thing is that the garbled characters only exist in the description in the table structure, but the inserted data is still normal in Chinese ~

I checked character_set_client=binary online and they said it was "mostly set to solve the garbled problem", but I didn't know that this description of the table structure was actually garbled. What exactly does this do? Why is the table structure different?

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326406.htmlTechArticleAfter the mysql link is established, set the encoding as follows: Copy the code as follows: mysql_query("SET character_set_connection=" . $GLOBALS['charset'] . ",character_set_results="...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn