select more than one row
void BaseMySQL::QueryArray(char *InQuery,std::string outResult[])
{
query_state = mysql_query(con, InQuery);
if (query_state !=0) {
printf("%s",mysql_error(con));
}
res = mysql_store_result(con);
m_fields = (WORD)mysql_num_fields(res);
while((row = mysql_fetch_row(res))!= NULL) {
for(int i = 0; i < 开发者_C百科m_fields; i++)
{
outResult[i]=row[i];
}
}
mysql_free_result(res);
}
the way this function am using works so lets say i have like 1000 account and my query is
"select id,name,password from account"
my function will just get me the 1st row like if am using std::string acc[20];//array
so
id=acc[0];
name=acc[1];
password=acc[2];
but my question which i cant figure it out how i can select all the rows and use it?
row = mysql_fetch_row(res);
while(row)
{
for(int i = 0; i < m_fields; i++)
{
outResult[i]=row[i];
}
row = mysql_fetch_row(res);
}
Change your function like this. Its working for me.
精彩评论