search
Homephp教程php手册In-depth Mysql character set settings, in-depth mysql character set

In-depth Mysql character set settings, in-depth mysql character set

There is a character set converter between the mysql client and the mysql server. character_set_client =>gbk: The converter knows that the encoding sent by the client is in gbk format character_set_connection=>gbk: Convert the data sent from the client into gbk format character_set_results =>gbk: ​ Note: The above three character sets can be set uniformly using set names gbk example: create table test( name varchar(64) NOT NULL )charset utf8;#utf8 here represents the server-side character encoding ​ First, insert a piece of data into the data table test inert into test values('test'); Then, the data "test" is saved in the "utf8" format in the database process:

​ First, the data is sent to the Mysql server through the mysql client. When passing through the character set converter, since the character_set_connection value is gbk, the data sent by the client will be converted into gbk format. Then, the character set converter will When the data is to be transmitted to the server, it is found that the server saves the data in utf8, so it will automatically convert the data from gbk to utf8 format internally. ​ When will garbled characters appear? Convert the client data into utf8 format through header('Content-type:text/html;charset=utf8'); when the data passes through the "character set converter", because character_set_client=gbk, character_set_connection is also equal to gbk , so the data transmitted from the client (actually in utf8 format) will not be converted. However, when the character set converter sends the data to the server, it finds that the format required by the server is utf8, so it will process the current data as gbk format and convert it to utf8 (however, this step Actually it's wrong. 2. When the result does not match the client page                      

Set the format of the returned result to utf8, but the format accepted by the client is gbk, so garbled characters will appear.
All available character sets can be displayed through the show character set syntax latin character set

Note: The Maxlen column shows the maximum number of bytes used to store a character. ​ utf8 character set

​ gbk character set

When will data be lost? Comparing the above three pictures, we can know that the maximum number of bytes used to store a character is different in each character set, with utf8 being the largest and latin being the smallest. Therefore, if it is not handled properly when passing through the character set converter, data will be lost and it will be irreparable. for example: When changing the value of character_set_connection to lantin

The gbk data sent from the client will be converted into lantin1 format, because the data in gbk format takes up more characters, which will cause data loss. ​

Summary:
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment