MySQL based on Linux by C

发表于:2007-07-02来源:作者:点击数: 标签:
int LoginJudge(USER_A CC OUNT 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,"server

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;
}

原文转自:http://www.ltesting.net