如何将MYSQL查询结果赋值给一个变量

2024-12-20 05:46:07
推荐回答(4个)
回答1:

sprintf(query, "SELECT *FROM history WHERE serialnumber='%s' AND adtcode='%s' LIMIT 1;", dataStr,modulename);
if (!mysql_real_query(mysql, query, (unsigned long)strlen(query))) {
res = mysql_use_result(mysql);
numfields = mysql_field_count(mysql);
while (row=mysql_fetch_row(res)) {
fprintf(outfile, "\r\n");
lengths = mysql_fetch_lengths(res);
fields=mysql_fetch_fields(res);
for (i=0; ifprintf(outfile, "%.*s ", (int)lengths[i], row[i]);
}
}

回答2:

sel 变量名 = (sel 字段 from table where ...)

回答3:

select 字段 into 变量 from 表明 where id = i;

回答4:

set @c =( select count(*) from shul );