pans
2016-12-30 dfa10a0616074fd82703516a2d3ef0f44cac64ab


git-svn-id: http://192.168.1.226/svn/proxy@66 454eff88-639b-444f-9e54-f578c98de674
3个文件已修改
58 ■■■■■ 已修改文件
RtspFace/demo/src/db/DBuntil.cpp 42 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
RtspFace/demo/src/db/DBuntil.h 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
RtspFace/demo/src/db/main.cpp 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
RtspFace/demo/src/db/DBuntil.cpp
@@ -8,18 +8,22 @@
MYSQL_RES *result;
MYSQL_ROW sql_row;
DBuntil::() {}
DBuntil::DBuntil(){}
DBuntil::DBuntil(my_db mydb)
{
    if(mysql_init(&myCont)!=NULL) {
    if(mysql_init(&myCont)!=NULL)
    {
        std::cout<<"init succeed"<<std::endl;
    } else
    }
    else
        std::cout<<"init failed"<<std::endl;
    if(mysql_real_connect(&myCont, mydb->host, mydb->user, mydb->pswd, mydb->db, mydb->port, NULL, 0) != NULL) {
    if(mysql_real_connect(&myCont, mydb.host, mydb.user, mydb.pswd, mydb.db, mydb.port, NULL, 0) != NULL)
    {
        std::cout<<"mysql_real_connect succeed"<<std::endl;
    } else
    }
    else
        std::cout<<"mysql_real_connect failed"<<std::endl;
}
@@ -46,15 +50,21 @@
    mysql_query(&myCont, "SET NAMES utf8"); //设置编码格式
    res = mysql_query(&myCont,sql);//查询
    if (!res) {
    if (!res)
    {
        result = mysql_store_result(&myCont);
        if (result) {
            while (sql_row = mysql_fetch_row(result)) { //获取具体的数据
        if (result)
        {
            while (sql_row = mysql_fetch_row(result))
            {
                //获取具体的数据
                per->p_id = atoi( sql_row[0]);
                per->name = sql_row[1];
            }
        }
    } else {
    }
    else
    {
        std::cout<<"query sql failed!"<<std::endl;
        return false;
    }
@@ -66,12 +76,22 @@
    //
    sprintf( sql, "INSERT INTO user_info(NAME, img) VALUES('%s', NULL)" , per->name );
    res = mysql_query(&myCont,sql);
    if(!res) {
    if(!res)
    {
        sprintf( sql, "INSERT INTO face_person(p_id, face_id) VALUES (LAST_INSERT_ID(), %d)" , f_id );
        res = mysql_query(&myCont,sql);
        if(!res) {
        if(!res)
        {
            return true;
        }
    }
    return false;
}
int DBuntil::db_register(int f_id,person *per)
{
    if(db_add(f_id,per)){
        return true;
    }
    return false;
}
RtspFace/demo/src/db/DBuntil.h
@@ -9,12 +9,12 @@
};
struct my_db {
    char user[];
    char pswd[];
    char host[];
    char db[];
    char user[25];
    char pswd[25];
    char host[25];
    char db[25];
    unsigned int port;
}
};
class DBuntil
{
@@ -25,7 +25,7 @@
    ~DBuntil();
    person db_rearch(int f_id);
    int db_register(int f_id,person p);
    int db_register(int f_id,person *p);
private:
RtspFace/demo/src/db/main.cpp
@@ -12,8 +12,8 @@
    my_db mydb={"root","Basic@2017","localhost","demo",3306};
    
    DBuntil dbu = DBuntil(mydb);
    person p={,"test"};
    if(dbu.db_add(i,p)){
    person p={0,"test"};
    if(dbu.db_register(i,&p)){
        cout<<"add succeed"<<endl;
    }else
        cout<<"add false"<<endl;