#2
星系隐2020-01-20 16:34
|
#include <winsock.h> //最好放在首位,位置关系会导致错误,mysql.h
#include "D:/新建文件夹/wamp/bin/mysql/mysql5.7.19/include/mysql.h"
#pragma comment (lib, "libmysql.lib")
#include <stdio.h>
#include <string.h>
#include <windows.h>
main(){
MYSQL * con; //= mysql_init((MYSQL*) 0);
MYSQL_RES *res;
MYSQL_ROW row;
char tmp[400];
//database configuartion
char dbuser[30]="root";
char dbpasswd[30]="";
char dbip[30]="127.0.0.1";
char dbname[50]="数据库0";
char tablename[50]="表0";
char *query=NULL;
int x;
int y;
int rt;//return value
unsigned int t;
int count = 0;
con = mysql_init((MYSQL*) 0);
if ( con !=NULL && mysql_real_connect(con,dbip,dbuser,dbpasswd,dbname,3306
/*TCP IP端口*/,NULL/*Unix Socket 连接类型*/,0/*运行成ODBC数据库标志*/) )
{
if (!mysql_select_db(con,dbname))
{
printf("Select successfully the database!\n");
con ->reconnect = 1;
query = "set names \'GBK\'";
//mysql_query(con,"set names \'GBK\'");
rt=mysql_real_query(con,query,strlen(query));
if (rt)
{
printf("Error making query: %s !!!\n",mysql_error(con));
}
else
{
printf("query %s succeed!\n",query);
}
}
}
else
{
MessageBoxA(NULL,"Unable to connect the database,check your configuration!","",NULL);
}
}
这段代码把数据库和表名改成英文的就能连接,汉字就不行,这该怎么办?orz,我是vc6做的代码,mysql.h和lib高手们改一下路径复制一下..跪求解决办法