VC读取SQL中中文字段问题
WinXP,MySql5.0.27,VC++6.0
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| name | varchar(20) | YES | | NULL | |
| bk | char(20) | YES | | NULL | |
| num | int(11) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
VC++读取下面的记录
+----------+----------+------+
| name | bk | num |
+----------+----------+------+
| a我是神b | c还是神d | 1 |
+----------+----------+------+
显示为
a???b c???d 1
察看内存
97,63,63,63,98
a ,? ,? ,? ,b
不像是乱码问题
具体代码如下:
#include "stdafx.h"
#include <winsock.h>
#include "F:\\MySQL50\\include\\mysql.h"
#pragma comment(lib,"F:\\MySQL50\\lib\\debug\\libmysql.lib")
int main(int argc, char* argv[])
{
MYSQL ms;
MYSQL_RES *mrs;
MYSQL_ROW row;
int res;
int i;
mysql_init(&ms);
if(!mysql_real_connect(&ms,"127.0.0.1","root","huahua","coco",0,NULL,0))
{
printf("Connect Failed!\n");
return 0;
}
res=mysql_query(&ms,"select * from pet");
if(res)
{
printf("mysql_query failed!");
return 0;
}
else
{
mrs=mysql_store_result(&ms);
res=mysql_num_fields(mrs);
while((row=mysql_fetch_row(mrs)))
{
for(i=0;i<res;i++)
{
printf("%s\t",row);
}
printf("\n");
}
mysql_free_result(mrs);
}
mysql_close(&ms);
return 0;
}
在printf("%s\t",row);处设断点,察看row的内存
row[0][0] 97,'a'
row[0][1] 63,'?'
row[0][2] 63,'?'
row[0][3] 63,'?'
row[0][4] 98,'b'
row[1] 'c???d'
row[2] '1'
不知这是什么问题
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | gb2312 |
| character_set_connection | gb2312 |
| character_set_database | gbk |
| character_set_filesystem | binary |
| character_set_results | gb2312 |
| character_set_server | gb2312 |
| character_set_system | utf8 |
| character_sets_dir | F:\MySQL50\share\charsets\ |
+--------------------------+----------------------------+