MySQL Coding mechanism _mysql

Source: Internet
Author: User
Character_set_client, this is what character set the user tells the MySQL query to use.
Character_set_connection, MySQL receives the user query, according to the character_set_client to convert it to character_set_connection set the character set.
Character_set_results, MySQL converts the stored data into character_set_results set in the character set sent to the user.
Discuz does not use set NAMES character
The SET NAMES ' x ' statement is equivalent to these three statements:
mysql> SET character_set_client = x; mysql> SET character_set_results = x; mysql> SET character_set_connection = x;
and Discuz inside is
Copy Code code as follows:

@mysql_query ("SET character_set_connection= $dbcharset, character_set_results= $dbcharset, character_set_client= Binary ", $this->link);

Set character_set_client = binary; use binary character set query
These three characters set to a large extent will solve the garbled problem, then three sets of specific what role?
character_set_clientSpecifies the encoding of the SQL statement, if set to Binary,mysql as binary processing, character_set_connection specifies the encoding that MySQL uses to run the SQL statement, that is, the SQL statement that the program sends to MySQL , it is first converted from the encoding specified by MySQL from character_set_client to character_set_connection-specified encoding, if character_set_clien specifies binary, MySQL will interpret the SQL statement as specified in Character_set_connection.
When executing an SQL statement, such as inserting a field into a database, the field also has an encoding setting, and if the encoding setting for the field differs from the character_set_connection specified, MySQL converts the inserted data into a field-set encoding. Conditional judgments in SQL statements are similar to the execution of SQL INSERT statements.
When the SQL executes like the client returns data, the data is converted from the specified encoding of the field to the Character_set_results specified encoding, and if Character_set_results=null does not do any conversion action, (Note that this setting to NULL does not mean that there is no setting, MySQL will inherit the global settings when there is no setting),
The work is more useful is to use MySQL for transcoding, different coded database sharing data.

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.