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

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

WBOY
WBOYOriginal
2016-06-01 13:44:251036Durchsuche

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

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn