MySQL C API : check if a field exists

标签 mysql c linux

我是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/

相关文章:

mysql - SQL 按另一列选择具有最新日期时间组的行

mysql - 将 SQL 查询转换为 MySQL 5.7.23

Linux:为了使用 emacs,将 Windows 键映射到 M-x

android - Phonegap : Getting Started with Android?——在 Linux 上

c - 我必须先对学生记录进行排序,然后再按名称排序

linux - 无法连接到在 guest 计算机上运行的 IM 服务器

mysql - 一张大 table 或多张小 table ,效率/良好实践

mysql - 如何在 mySQL 中将日期转换为字符串?

c - 使字符串比较函数更简短

c - 用 C 制作一个小的 mach-o 可执行文件