问题描述
在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
但是,在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结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!