// mysqlCon.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include "winsock2.h" #pragma comment(lib,"./inc/libmysql.lib") #include "./inc/mysql.h" MYSQL _sql; bool updateUser(int userID,char *nickName) { char cmd[256]; sprintf(cmd,"update user set nickName='/%s/'where userID='/%d/'",nickName,userID); if(mysql_real_query(&_sql,cmd,strlen(cmd))!=0) { return false; } return true; } bool insertUser(int userID,char *userName,char *nickName,char *pwd) { char cmd[256]; sprintf(cmd,"insert into user(userID,userName,nickName,pwd)values('/%d/','/%s/','/%s/','/%s/')",userID,userName,nickName,pwd); if(mysql_real_query(&_sql,cmd,strlen(cmd))!=0) { return false; } return true; } bool insertIPMap(int userID,char *ip) { char cmd[256]; sprintf(cmd,"insert into ipmap(userid,ip)values('/%d/','/%s/')",userID,ip); if(mysql_real_query(&_sql,cmd,strlen(cmd))!=0) { return false; } return true; } bool del(int userID) { char cmd[256]; sprintf(cmd,"delete from user where userid=/'%d/'",userID); if(mysql_real_query(&_sql,cmd,strlen(cmd))!=0) { return false; } return true; } int _tmain(int argc, _TCHAR* argv[]) { mysql_init(&_sql); if (mysql_real_connect(&_sql,"localhost","root","","lkdb",3306,0,0)) { printf("connect ok/n"); } int userid = 100002; if (insertIPMap(userid,"127.0.0.1")) { printf("insert ipmap ok/n"); } if (insertUser(userid,"m1","m1","123456")) { printf("insert user ok/n"); } //userid = 100001; if (updateUser(userid,"hello")) { printf("update user ok/n"); } system("pause"); mysql_close(&_sql); return 0; }