MySQl C API 如何使用字段名访问记录:例如:row 如何按字段名访问了,PHP可以使用域访问: row["id"],mysql c库里不支持。int db_get_config()
{
MYSQL_RES *rs=0;
MYSQL_ROW row;
int ret,rows,cols,i;
char sql_str[]="SELECT * FROM config"; ret=mysql_query(&mysql_conn,sql_str);
if(ret){
debug_error("mysql_query fails: ");
goto error;
}
rs=mysql_store_result(&mysql_conn);
if(!rs){
debug_error("mysql_store_result fails: ");
goto error;
}
rows=0;//mysql_num_rows(rs);
cols=4;//mysql_field_count(&mysql_conn);
debug_db("rows=%d,cols=%d\n",rows,cols);
while (row = mysql_fetch_row(rs)) {/* Fetch one by one */
for (i = 0; i < 4; i++)
{
#if 0//test chinese charset is support ?
debug_db("==> [0x%02x%02x%02x%02x]\n", row[3][0],row[3][1],row[3][2],row[3][3]);
#else
debug_db("==> %s\n", row("memo"));
#endif
}
}
ret=0;
goto result;error:
debug_error("%s\n",mysql_error(&mysql_conn));
ret=-1;
result:
if(rs){
mysql_free_result(rs);
}
return ret;
}
{
MYSQL_RES *rs=0;
MYSQL_ROW row;
int ret,rows,cols,i;
char sql_str[]="SELECT * FROM config"; ret=mysql_query(&mysql_conn,sql_str);
if(ret){
debug_error("mysql_query fails: ");
goto error;
}
rs=mysql_store_result(&mysql_conn);
if(!rs){
debug_error("mysql_store_result fails: ");
goto error;
}
rows=0;//mysql_num_rows(rs);
cols=4;//mysql_field_count(&mysql_conn);
debug_db("rows=%d,cols=%d\n",rows,cols);
while (row = mysql_fetch_row(rs)) {/* Fetch one by one */
for (i = 0; i < 4; i++)
{
#if 0//test chinese charset is support ?
debug_db("==> [0x%02x%02x%02x%02x]\n", row[3][0],row[3][1],row[3][2],row[3][3]);
#else
debug_db("==> %s\n", row("memo"));
#endif
}
}
ret=0;
goto result;error:
debug_error("%s\n",mysql_error(&mysql_conn));
ret=-1;
result:
if(rs){
mysql_free_result(rs);
}
return ret;
}
从fields里提取字段名,然后匹配到第几列,最后找出对应值。
不知道如何做?