我是c语言上的mysql编程新手。我需要检查表中是否存在某个用户。我如何使用 C API 来做到这一点? 这是我所拥有的,但它不起作用:
if (mysql_query(con, "SELECT * FROM Users WHERE UserName='user3'"))
{
finish_with_error(con);
}
MYSQL_RES *result = mysql_store_result(con);
if (result == NULL)
{
finish_with_error(con);
}
int count = mysql_field_count(con);
printf("%d\n", count );
最佳答案
对于任何感兴趣的人,这是我使用评论编写的内容,最终使用了。
if (mysql_query(con, "SELECT field FROM table WHERE userName='user1'"))
{
finish_with_error(con);
}
MYSQL_RES *result = mysql_store_result(con);
if (result == NULL)
{
finish_with_error(con);
}
MYSQL_ROW row;
MYSQL_FIELD *field;
if (row = mysql_fetch_row(result))
{
printf("%s\n", row[0]);
db_pwd = row[0];
}
关于MySQL C API : check if a field exists,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25968515/