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;
61 cout<<
"You are reconnecting!"<<endl;
71 cout<<
"You must connect before select db!";
74 if(mysql_select_db(m_Mysql,db.c_str()))
76 cout<<
"Select database error!"<<endl;
86 if((!m_bConnect)||(!m_bSelectDB))
88 cout<<
"You executing query before connection or select db!"<<endl;
95 if(m_strQuery.empty())
97 cout<<
"Your haven't set query string!"<<endl;
103 if(mysql_real_query(m_Mysql,m_strQuery.c_str(),m_strQuery.size()))
105 cout<<
"Execute query error!"<<endl;
114 else {m_result=
true;}
116 m_Res = mysql_store_result(m_Mysql);
125 cout<<
"You must execute query before get row!"<<endl;
130 if(row>=mysql_num_rows(m_Res)||row<0)
135 mysql_data_seek(m_Res,row);
137 m_Row=mysql_fetch_row(m_Res);
140 cout<<
"fetch_row error!"<<endl;
153 cout<<
"You must get a row before getfield value!"<<endl;
156 if(m_Row[n]!=NULL){
return (
string)m_Row[n];}
175 cout<<
"error:no select!"<<endl;
178 m_field = mysql_fetch_field_direct(m_Res, n);
179 return string(m_field->name);
195 cout<<
"You are get number of rows before execute!"<<endl;
198 return mysql_num_rows(m_Res);
205 mysql_free_result(m_Res);
216 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)