MySQL based on Linux by C

类别:数据库 点击:0 评论:0 推荐:

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://com.8s8s.com/it/it21675.htm