数据库名和表名用了中文,连接不上怎么办?
#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);
}
}
运行时连接不上..改英文就行,我想问问怎么用连接上中文的?我觉得可能是字符编码问题?