22 Init(host,user,passwd,db);
46 if(!(m_Mysql=mysql_init(
NULL)))
48 cout<<
"Init mysql error!!"<<endl;
52 if(!mysql_real_connect(m_Mysql,m_strHost.c_str(),m_strUser.c_str(),m_strPasswd.c_str(),m_strDB.c_str(),0,
NULL,0))
54 cout<<
"Connect error!!"<<endl;
57 cout<<
"Reconnect ..."<<endl;
59 if(mysql_real_connect(m_Mysql,m_strHost.c_str(),m_strUser.c_str(),m_strPasswd.c_str(),m_strDB.c_str(),0,
NULL,0))
61 cout<<
"Reconnect success"<<endl;
65 cout<<
"Reconnect fail"<<endl;
73 cout<<
"You are reconnecting!"<<endl;
83 cout<<
"You must connect before select db!";
86 if(mysql_select_db(m_Mysql,db.c_str()))
88 cout<<
"Select database error!"<<endl;
98 if((!m_bConnect)||(!m_bSelectDB))
100 cout<<
"You executing query before connection or select db!"<<endl;
107 if(m_strQuery.empty())
109 cout<<
"Your haven't set query string!"<<endl;
115 if(mysql_real_query(m_Mysql,m_strQuery.c_str(),m_strQuery.size()))
117 cout<<
"Execute query error!"<<endl;
126 else {m_result=
true;}
128 m_Res = mysql_store_result(m_Mysql);
137 cout<<
"You must execute query before get row!"<<endl;
142 if(row>=mysql_num_rows(m_Res)||row<0)
147 mysql_data_seek(m_Res,row);
149 m_Row=mysql_fetch_row(m_Res);
152 cout<<
"fetch_row error!"<<endl;
165 cout<<
"You must get a row before getfield value!"<<endl;
168 if(m_Row[
n]!=
NULL){
return (
string)m_Row[
n];}
187 cout<<
"error:no select!"<<endl;
190 m_field = mysql_fetch_field_direct(m_Res,
n);
191 return string(m_field->name);
207 cout<<
"You are get number of rows before execute!"<<endl;
210 return mysql_num_rows(m_Res);
217 mysql_free_result(m_Res);
228 mysql_close(m_Mysql);
bool GetRow(my_ulonglong row=NEXT_ROW)
string GetField_name(unsigned int n)
unsigned long Num_Rows(void)
void SetQuery(string query)
void Init(string host, string user, string passwd, string db="")
bool Execute(string query="")
string GetField(unsigned int n)