在PDO :: commit之后使用PDOStatement :: rowCount结果? [英] PDOStatement::rowCount result when used after PDO::commit?

查看:96
本文介绍了在PDO :: commit之后使用PDOStatement :: rowCount结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MySQL文档中,有关于在事务提交后使用mysql_affected_rows的说明: http://php.net/manual/en/function.mysql-affected-rows.php

In the MySQL docs, there is a note about using mysql_affected_rows after a transaction commit: http://php.net/manual/en/function.mysql-affected-rows.php

注意:交易
如果使用事务,则需要在INSERT,UPDATE或DELETE查询之后而不是COMMIT之后调用 mysql_affected_rows().

Note: Transactions
If you are using transactions, you need to call mysql_affected_rows() after your INSERT, UPDATE, or DELETE query, not after the COMMIT.

但是,在PDOStatement::rowCount文档中没有这样的注释: http://www.php.net/manual/en/pdostatement.rowcount.php

However, there is no such note on the PDOStatement::rowCount doc: http://www.php.net/manual/en/pdostatement.rowcount.php

这是否意味着在使用PDO对象时,提交不会影响INSERT,UPDATE或DELETE查询后受影响的行数吗?

Does this mean the commit will not affect the affected rows count after INSERT, UPDATE or DELETE queries when using the PDO object?

推荐答案

对于每个执行的查询,都会返回一个PDOStatement.您可以在代码中的任何时候使用PDOStatement-> rowCount()(在事务期间或之后,回滚/提交无关紧要).每个对象都要维护自己.

A PDOStatement is returned for each query that is executed. You will be able to use PDOStatement->rowCount() at any time in your code (during or after a transaction and rollback/commit doesn't matter). Each object takes care of maintaining itself.

mysql_affected_rows拥有该事务注释的原因是因为它仅知道单个mysql连接资源.这意味着当您完成事务(提交/回滚)时,新查询已发送到数据库,从而更改了针对受影响的行数正在处理的结果.

The reason mysql_affected_rows has that transaction note is because it is only aware of a single mysql connection resource. This means that when you complete the transaction (commit/rollback) a new query has been sent to the DB, thus altering which result is being processed for the number of affected rows.

这篇关于在PDO :: commit之后使用PDOStatement :: rowCount结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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