Solution for mysql CAPI interface to read Chinese garbled characters

Source: Internet
Author: User

 

In the recent open-source project of yymysqlsdk, Chinese support is not in place. Therefore, it took 1.5 days to analyze various Chinese processing conditions.

 

 

 

1. First confirm your mysql configuration file, my. ini (only for windows) configuration, if not, add

 

[Client]

 

Default-character-set = gbk (it is used to support Chinese characters when developing the client program. If it is set to utf8, I have not verified it. I will verify it later, haha)

 

[Mysql]

 

Default-character-set = utf8

 

[Mysqld]

 

Default-character-set = utf8

 

2. For database encoding attributes, select utf8. I am using naticat mysql.

 

3. Right-click the table and choose "query table information"> "ddl". Does the system see "ENGINE = InnoDB default charset = latin1 ;"

 

By the way, this is the default encoding method used by naticat when designing a table. Please do not change this encoding method as needed. latin1 is compatible with utf8)

 

4. Then, use vc to develop the client program. After real_connect, execute the encoding settings, mysql_query (xxx, "set names latin1 ");

 

5. Check the code,

 

View plain

Int rows = mysql_num_rows (res );

 

Int fields = mysql_num_fields (res );

 

For (int I = 0; I <rows; I ++)

{

MYSQL_ROW row = mysql_fetch_row (res );

 

Unsigned long * lengths = mysql_fetch_lengths (res );

 

For (int j = 0; j <fields; j ++)

{

Printf ("% s \ n", row [j]);

 

 

 

6. At this time, the output is utf8 encoded, Chinese

 

 

 

The above is my summary. I would be honored to help you.

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.