1

I want to know when an UPDATE query reports 0 rows matches. I'm using libmysql.

Here's the code I'm using:

char query[300] = {0};
snprintf(query, 300, "UPDATE `my_table` SET name='%s' WHERE id=%d",
         name, id);

if (mysql_query(db, query)) {
    printf("Error!\n");
}

Essentially what I need to know is whether or not there is a match for id. I know I can check that by doing a select, but is there another way?

4

1 回答 1

2

检查mysql_affected_rows。这将返回最后一个查询修改的行数。

但是,它可能只返回实际修改的行。如果要返回匹配的行,则必须CLIENT_FOUND_ROWSmysql_real_connect. 详情请查看同一页面。

于 2016-01-27T07:05:47.277 回答