日期:2014-05-16 浏览次数:20911 次
bool query(unsigned int ip,string &city,string &country)
{
char sql[256];
memset(sql,0,256);
sprintf_s(sql,256,"select country,city FROM citylocation where LocId = (select LocId from ipindex where startIpNum <= %u and endIpNum >= %u limit 1)",ip,ip);
DWORD start,end;
start = GetTickCount();
if( mysql_real_query(mysql,sql,strlen(sql)) !=0 )
return false; // 查询失败
end = GetTickCount();
cout << end - start << " " << endl; //查询时间
MYSQL_RES *rs=mysql_store_result(mysql);
if(rs != NULL)
{
MYSQL_ROW row;
if((row = mysql_fetch_row(rs)) == NULL)
return false;
if(row[0] != NULL)
country = row[0];
if(row[1] != NULL)
city = row[1];
free_result(rs);
return true;
}
return false;
}