3

我想在 C 中使用来自 mysql 数据库的 Select 查询:

mysql_query(conn,"SELECT SI AS SUBSCRIBER_ID ,TG2 AS TAG_ID, SUM(CTR) AS NBR FROM (SELECT H.SUBSCRIBER_ID AS SI, TG.TAG_ID AS TG1,T.TAG_ID AS TG2, COUNT(TG.TAG_ID) AS COUNTER,CASE WHEN (TG.TAG_ID = T.TAG_ID) THEN COUNT(TG.TAG_ID) ELSE 0 END AS CTR from content_hits H left join  CONTENT_TAG TG ON TG.CONTENT_ID = H.CONTENT_ID LEFT JOIN TAG T ON 1= 1 GROUP BY H.SUBSCRIBER_ID, TG.TAG_ID,T.TAG_ID) AS TAB GROUP BY SI,TG2");

之后,我想使用“NBR”来填充一维数组。

我试过这个:

result = mysql_store_result(conn);

while ((row = mysql_fetch_row(result)))
{
  t[i]=*row['NBR'];
  printf("%d",t[i]);
}

但它没有用。

4

1 回答 1

2

您不能像您一样按名称访问行列 t[i]=*row['NBR'];。例如fields = mysql_fetch_fields(result);,用于获取列名并遍历字段数组以查找 id 'NBR' 具有的列。然后这个 id 可以用在t[i]=row[id];. 这一切都在 mysql 连接器文档http://dev.mysql.com/doc/refman/5.0/en/mysql-fetch-fields.html

于 2012-04-11T10:45:06.290 回答