MySQL based on Linux by C
int loginjudge(user_account req)
{
int i=0;
char *name;
char *reqname;
char *password;
char *reqpass;
reqname=req.name;
reqpass=req.password;
if(!(mysql_connect(&mysql,null,\"root\",\"1111\")))
return false;
if(mysql_select_db(&mysql,\"serverdb\"))
return false;
if (mysql_query(&mysql,\"select name,password from main\" ))
return false;
if(!(res=mysql_store_result(&mysql)))
return false;
while((row=mysql_fetch_row(res)))
{
name=row[0];
password=row[1];
if (!strcmp(name,reqname))
{
if(!strcmp(password,reqpass))
return true;
else
return false;
}
}
if(! mysql_eof(res))
return false;
mysql_free_result(res);
mysql_close(&mysql);
return false;
}
int authority(char *name)
{
long ibackvalue;
char *cdbname;
char *cdbauthority;
char *cquename;
char *cvalueone;
char *cvaluetwo;
cquename=name;
cvalueone=\"1\";
cvaluetwo=\"2\";
if(!(mysql_connect(&mysql,null,\"root\",\"1111\")))
return false;
if(mysql_select_db(&mysql,\"serverdb\"))
return false;
if (mysql_query(&mysql,\"select name,authority from main\" ))
return false;
if(!(res=mysql_store_result(&mysql)))
return false;
while((row=mysql_fetch_row(res)))
{
cdbname=row[0];
cdbauthority=row[1];
if (!strcmp(cdbname,cquename))
{
if(!strcmp(cvalueone,cdbauthority))
{
ibackvalue=1;
if(!strcmp(cvaluetwo,cdbauthority))
ibackvalue=2;
}
else
ibackvalue=3;
}
}
if(! mysql_eof(res))
return false;
mysql_free_result(res);
mysql_close(&mysql);
return ibackvalue;
}
发布人:Crystal 来自:中国软件