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

查看:73
本文介绍了有什么方法可以区分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
  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天全站免登陆