PDO-检查行是否已更新? [英] PDO - check if row was updated?

查看:87
本文介绍了PDO-检查行是否已更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其他人问了这个问题,但是我的要具体一些.

Other people have asked this question, but mine is a little more specific.

我有这个查询:

$sql = "UPDATE table SET option=? WHERE number=?";
$q = $conn->prepare($sql);
$q->execute(array($option, $number));
$q->setFetchMode(PDO::FETCH_BOTH);

echo $q->rowCount();

如果WHERE number已经存在并且SET option相同,则$q->rowCount()等于0

If the WHERE number already exists and the SET option is same, $q->rowCount() equals 0

如果WHERE number不存在并且行不更新,则$q->rowCount()等于0

If the WHERE number doesnt exist and the row does not update, $q->rowCount() equals 0

如何区分这些非更新?

推荐答案

在最新的PHP版本中,它由PDO::MYSQL_ATTR_FOUND_ROWS属性控制. 当设置为true时,根据 doc ,效果是:

On recent PHP versions, it's controlled by the PDO::MYSQL_ATTR_FOUND_ROWS attribute. When set to true, according to the doc, the effect is:

Return the number of found (matched) rows, not the number of changed rows.

这篇关于PDO-检查行是否已更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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