Home > Database > Mysql Tutorial > body text

mysql CAPI 接口 读取中文乱码的解决方案_MySQL

WBOY
Release: 2016-06-01 13:44:25
Original
1035 people have browsed it

bitsCN.com

 

最近的yymysqlsdk的开源项目里,对中文的支持不到位,因此用了1.5天的时间,对中文处理的各个情况进行了分析。

 

 

 

1.首先确认你的mysql配置文件,my.ini (只针对windows)里的配置,如没有则添加

 

[client]

 

default-character-set=gbk (是为了,开发客户端程序时,对中文的支持;如果此处设置为utf8,我没有验证过,稍后验证,哈哈)

 

[mysql]

 

default-character-set=utf8

 

[mysqld]

 

default-character-set=utf8

 

2.数据库编码属性,选择utf8,我使用的是naticat mysql。

 

3.具体到表,右键查询表信息-》ddl ,有没有 看到 一句 “ENGINE=InnoDB DEFAULT CHARSET=latin1;”

 

对了,这就是设计表的时候,naticat 默认使用的编码方式,请不要随影更改此编码方式,latin1是兼容对utf8的支持(瞎猜的)

 

4.然后就是用vc去开发客户端程序了,在real_connect后,请执行 编码设置,mysql_query(xxx,“set names latin1”);

 

5.看代码吧,

 

view plain

int rows = mysql_num_rows(res); 

 

int fields = mysql_num_fields(res); 

 

for (int i=0;i

    MYSQL_ROW row = mysql_fetch_row(res); 

 

    unsigned long *lengths = mysql_fetch_lengths(res); 

 

    for (int j=0;j

    { 

        printf("%s/n",row[j]); 

 

 

 

6.此时输出的就是utf8编码的,中文

 

 

 

以上就是我的总结,如对您有帮助,我不胜荣幸。

bitsCN.com

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!