mysql - 如何知道使用 Update 查询更新的记录?

标签 mysql c

如何知道表中的任何记录是否被更新查询更新。

我正在使用 Mysql C API..我尝试在触发 UPDATE 查询后存储 mysql 结果,但结果总是返回 NULL 以成功更新。任何帮助都会很棒。

谢谢

 int main(void)                                                                                       
{                                                                                                    
  MYSQL *conn;                                                                                       
  MYSQL_RES *res;
  MYSQL_ROW row;

  if ((conn = mysql_init(NULL)) == NULL)                                                             
  {                                                                                                  
    fprintf(stderr, "Could not init DB\n");                                                 
    return EXIT_FAILURE;                                                                             
  }                                                                                                  
  if (mysql_real_connect(conn, "localhost", "root", "password", "cpaas", 0, NULL, 0) == NULL)             
  {                                                                                                  
    fprintf(stderr, "DB Connection Error\n");                                                        
    return EXIT_FAILURE;                                                                             
  }                                                                                                  
  if (mysql_query(conn, "update calldirection set callid='Hello' where callid='He'") != 0)                   
  {                                                                                                  
    fprintf(stderr, "Query Failure\n");                                                              
    return EXIT_FAILURE;                                                                             
  }
  res = mysql_store_result(conn);

  if(res == NULL){
    printf("dssdg");
    return 1;
  }
  if ((row = mysql_num_rows(res)) <= 0)
        {
                printf("FFFFFFF");
        }


  mysql_close(conn);                                                                                 
  return EXIT_SUCCESS;                                                                               
}

最佳答案

在进行了近 1 天的研发之后...我发现了 mysql_affected_rows(*mysql) 函数,它将返回为 UPDATE 查询更新的行数。

关于mysql - 如何知道使用 Update 查询更新的记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58761396/

相关文章:

mysql - 如何通过水平滚动从数据库填充xamarin表单gridview数据

c++ - 将函数声明为 pure 或 const 对 GCC 的影响(如果不是)

从 Matlab 到 C 的 Cholesky 分解函数

c++ - 在 amd64 Debian 上编译 i386 二进制文件?

c - GTK Linux C 通过按钮小部件从输入框获取输入

mysql - 从包含多条数据的列中获取一条数据

mysql - 与 SQL Server 相比,为什么 MySQL 中该表占用的磁盘空间是 SQL Server 的 10 倍?

mysql - “来自接口(interface)端点的客户端不允许访问服务器。请确保您的虚拟网络配置正确。 (SQL 状态 28000)

c# - 为什么在 C# .Net Core 3 中连接到 MySql 时出现错误

c - Pthread 创建为分离