MySQL stores the difference between full-width characters and half-width characters. mysql stores full-width and half-width characters.

Source: Internet
Author: User

MySQL stores the difference between full-width characters and half-width characters. mysql stores full-width and half-width characters.

Unfortunately, the company encountered the MYSQL_DATA_TRUNCATED error when testing IM, and the log record still appeared when mysql_stmt_fetch was called. In view of the previous experience, it should be caused by the insufficient length of the binding area of the given result set. No problem was found after repeated checks. I have a correspondence relationship in the Code, such as char (20). In my code, the char buffer [20] array is defined for storage. It seems so correct and perfect. There is no way to print the data of each row, find the line of the error record, and find the font is different from other. For example:

123456789 (halfwidth)
123456789 (full angle)

This is not controlled by spaces, but by full-width control of input methods. For full-width characters, it is twice the length of half-width characters, while MySQL uses UTF-8, so in the database, it is a full-width character with a length of three bytes.

Select length (column) from table_name where ...;

Use this to print the length. At this time, you need to consider the problem that the type length in the code matches the database Field Length, such as full-width or Chinese characters. In the database, char (20) represents 20 characters rather than 20 bytes, therefore, do not use this 20 as the result set length to retrieve 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.