MySQL based on Linux by C (轉)

worldblog發表於2007-12-23
MySQL based on Linux by C (轉)[@more@]

int LoginJudge(USER_ACCOUNT req)
{

  int i=0;
 char *name;
 char *reqname;
 char *pass;
 char *reqpass;
 reqname=req.Name;
 reqpass=req.Password;

 if(!(my_connect(&,NULL,"","1111")))
 return FALSE;
 if(mysql__(&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 *cuthority;
 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;
}


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-995511/,如需轉載,請註明出處,否則將追究法律責任。

相關文章