近期转到研发岗,需要用到mysql、vs2008;之前由于没有做过,写下这篇文章记录下这周所学的东西!
先安装好相关软件
安装时间比较久耐心等待......
安装完毕之后打开vs,Tools -> opptions ->
设置完毕之后,点击ok!
然后点击项目属性 如图设置
部分代码(不全):
MYSQL mysql;
mysql_init(&mysql);
if(!mysql_real_connect(&mysql, g_DbIp, g_DbUser, g_DbPwd, "DATAMON_DB", 3306, NULL, 0))
{
throw ERROR_DB;
}
char szCurTime[64] = {0};
GetDateTimeString("%Y-%m-%d %H:%M:%S",szCurTime,sizeof(szCurTime));
sprintf_s(buf,sizeof(buf),"insert into MXBYJ_FILES_TBL(FILENAME,MD5CODE,MACID,ISTRANS,CREATETIME,USERID) VALUES('%s','%s','%s',0,'%s','%d')",
fileInfo.filename[nIndex].c_str(),fileInfo.md5code[nIndex].c_str(),fileInfo.macid.c_str(),szCurTime,fileInfo.userid);
if(0 != mysql_query(mysql, buf))
{
//有问题
fileInfo.errorstr = fileInfo.filename[nIndex].c_str();
fileInfo.errorstr += ";入库失败!sql:";
fileInfo.errorstr += buf;
fileInfo.errorstr += "\r\n";
return ERROR_DB;
}
sprintf_s(buf,sizeof(buf),"select FILEID from MXBYJ_FILES_TBL where FILENAME='%s'",fileInfo.filename[nIndex].c_str());
if(0 != mysql_real_query(mysql, buf, strlen(buf)))
{
//有问题
fileInfo.errorstr = fileInfo.filename[nIndex].c_str();
fileInfo.errorstr += ";查询文件ID失败!sql:";
fileInfo.errorstr += buf;
fileInfo.errorstr += "\r\n";
return ERROR_DB;
}
result = mysql_store_result(mysql);
if(NULL != result)
{
row = mysql_fetch_row(result);
if(NULL != row)
{
nFileID = atoi(row[0]);
fileInfo.fileid[nIndex] = nFileID;
}
else
{
fileInfo.errorstr = fileInfo.filename[nIndex].c_str();
fileInfo.errorstr += ";查询文件ID无记录!sql:";
fileInfo.errorstr += buf;
fileInfo.errorstr += "\r\n";
nFileID =ERROR_DB;
}
mysql_free_result(result);
}
ps:如果你编译的程序需要自动拷贝到某一个目录 进行测试 可以如下设置: