1.注册:检查用户名是否已经被用。
2.登录:自动检查帐号密码是否匹配。
#include <mysql/mysql.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
char logFlag;
string name;
string password1;
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char server[] = "localhost";
char user[] = "root";
char password[] = "123";
char database[] = "chat";
char time1[20]; //只要跟数据库有关的,定义都要以这种形式,不能char *time1不然会报错“段错误”
int GetCurTime(char *strTime,int type)
{
time_t t;
struct tm *tm = NULL;
t = time(NULL);
if(t == -1)
{
return -1;
}
tm = localtime(&t);
if(tm == NULL)
{
return -1;
}
if(type == 0)
sprintf(strTime,"系统运行时间为: %d-%d-%d %d:%d:%d\n",tm->tm_year + 1900,tm->tm_mon + 1,tm->tm_mday,tm->tm_hour,t