pans
2017-01-04 332d18eb6733a5400a2cfd3a3faa2e056bd2a02c
RtspFace/demo/src/DBuntil.cpp
@@ -8,7 +8,7 @@
MYSQL_RES *result;
MYSQL_ROW sql_row;
DBuntil::DBuntil(){}
DBuntil::DBuntil() {}
DBuntil::DBuntil(my_db mydb)
{
@@ -35,18 +35,21 @@
   mysql_close(&myCont);
}
*person DBuntil::db_rearch(int f_id)
bool DBuntil::db_search(person* per)
{
   person p= {0,""};
   db_select(f_id,&p);
   //对结构体赋值
   return &p;
   std::cout<<"db_search start"<<std::endl;
   if(db_select(per))
   {
      return true;
   }
   return false;
}
bool DBuntil::db_select(int f_id,person* per)
bool DBuntil::db_select(person* per)
{
   sprintf( sql, "select a.p_id,b.`name`,b.img from face_person a,user_info b where a.face_id = %d AND a.p_id = b.pid " , f_id );
   std::cout<<"db_select start"<<std::endl;
   sprintf( sql, "select a.p_id,b.`name`,b.img from face_person a,user_info b where a.face_id = %d AND a.p_id = b.pid " ,per->f_id );
   mysql_query(&myCont, "SET NAMES utf8"); //设置编码格式
   res = mysql_query(&myCont,sql);//查询
@@ -71,14 +74,14 @@
   return true;
}
bool DBuntil::db_add(int f_id,person *per)
bool DBuntil::db_add(person *per)
{
   //
   sprintf( sql, "INSERT INTO user_info(NAME, img) VALUES('%s', NULL)" , per->name );
   res = mysql_query(&myCont,sql);
   if(!res)
   {
      sprintf( sql, "INSERT INTO face_person(p_id, face_id) VALUES (LAST_INSERT_ID(), %d)" , f_id );
      sprintf( sql, "INSERT INTO face_person(p_id, face_id) VALUES (LAST_INSERT_ID(), %d)" , per->f_id );
      res = mysql_query(&myCont,sql);
      if(!res)
      {
@@ -88,9 +91,10 @@
   return false;
}
bool DBuntil::db_register(int f_id,person *per)
bool DBuntil::db_register(person *per)
{
   if(db_add(f_id,per)){
   if(db_add(per))
   {
      return true;
   }
   return false;