有什么方法可以区分 0 受影响的 MYSQL 更新行的情况吗? [英] Any way to distinguish the cases of 0 affected row of MYSQL update?

查看:25
本文介绍了有什么方法可以区分 0 受影响的 MYSQL 更新行的情况吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个名为 't' 的表

Suppose I have a table named 't'

---------------
| key | value |
---------------
| 1   | abc   |
| 2   | def   |
---------------

考虑两个 MYSQL 查询

Consider two MYSQL queries

  1. UPDATE t SET value='abc' WHERE key=1
  2. UPDATE t SET value='abc' WHERE key=3

执行这两个查询也会使受影响的行"为 0(即不更新任何行),因为第一个查询是非更新更新,第二个查询是非匹配更新.

Executing both queries also give the 'affected rows' is 0 (That is, do NOT update any row) because first query is an non-updating update and second is an non-matching update.

有没有办法区分这两种情况?

Is there any way to distinguish these two cases?

推荐答案

如果你只想要'匹配'的行数(不再需要'改变'的行数),你可以设置 CLIENT_FOUND_ROWS 如此处所述:

if you only want the number of 'matched' rows (and no longer the number of 'changed' rows), you can set CLIENT_FOUND_ROWS as described here:

http://dev.mysql.com/doc/refman/5.5/en/mysql-affected-rows.html

对于 UPDATE 语句,默认情况下受影响的行值是实际更改的行数.如果您指定 CLIENT_FOUND_ROWS连接到 mysqld 时标记 mysql_real_connect(),受影响的行值是找到"的行数;也就是说,匹配WHERE 子句.

For UPDATE statements, the affected-rows value by default is the number of rows actually changed. If you specify the CLIENT_FOUND_ROWS flag to mysql_real_connect() when connecting to mysqld, the affected-rows value is the number of rows "found"; that is, matched by the WHERE clause.

这篇关于有什么方法可以区分 0 受影响的 MYSQL 更新行的情况吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆