| | |
| | | #include <cstdio>
|
| | | #include <iostream>
|
| | |
|
| | | DBuntil::DBuntil() {
|
| | | |
| | | }
|
| | |
|
| | | DBuntil::DBuntil(my_db mydb)
|
| | | DBuntil::DBuntil()
|
| | | {
|
| | | std::cout<<"DBuntil(my_db mydb) start"<<std::endl;
|
| | | |
| | | if(mysql_init(&myCont)!=NULL)
|
| | | {
|
| | | std::cout<<"init succeed"<<std::endl;
|
| | | }
|
| | | 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)
|
| | | {
|
| | | std::cout<<"mysql_real_connect succeed"<<std::endl;
|
| | | }
|
| | | else
|
| | | std::cout<<"mysql_real_connect failed"<<std::endl;
|
| | | |
| | | std::cout<<"DBuntil(my_db mydb) end"<<std::endl;
|
| | | }
|
| | |
|
| | | DBuntil::~DBuntil()
|
| | |
| | | mysql_close(&myCont);
|
| | | }
|
| | |
|
| | | bool DBuntil::db_init(my_db mydb)
|
| | | {
|
| | | std::cout<<"db_init(my_db mydb) start"<<std::endl;
|
| | |
|
| | | if(mysql_init(&myCont)!=NULL)
|
| | | {
|
| | | std::cout<<"init succeed"<<std::endl;
|
| | | }
|
| | | 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)
|
| | | {
|
| | | std::cout<<"mysql_real_connect succeed"<<std::endl;
|
| | | std::cout<<"db_init(my_db mydb) end"<<std::endl;
|
| | | return true;
|
| | | }
|
| | | else
|
| | | {
|
| | | std::cout<<"mysql_real_connect failed"<<std::endl;
|
| | | }
|
| | | std::cout<<"db_init(my_db mydb) end"<<std::endl;
|
| | | return false;
|
| | | }
|
| | |
|
| | | bool DBuntil::db_search(person* per)
|
| | | {
|
| | | std::cout<<"db_search start"<<std::endl;
|
| | | //db_init()
|
| | | if(db_select(per))
|
| | | {
|
| | |
|
| | | return true;
|
| | | }
|
| | | return false;
|
| | |
| | | if(!mysql_query(&myCont, "SET NAMES utf8"))//设置编码格式
|
| | | {
|
| | | std::cout<<"SET NAMES utf8"<<std::endl;
|
| | | }else
|
| | | }
|
| | | else
|
| | | std::cout<<"SET NAMES utf8 failed"<<std::endl;
|
| | | res = mysql_query(&myCont,sql);//查询
|
| | | if (!res)
|
| | |
| | | std::cout<<"per->name="<<per->name<<std::endl;
|
| | | std::cout<<"per->f_id="<<per->f_id<<std::endl;
|
| | | }
|
| | | }else
|
| | | }
|
| | | else
|
| | | std::cout<<"result is null?"<<std::endl;
|
| | | }
|
| | | else
|