PDO:rowCount()和SQL COUNT(col)之间的差异 [英] PDO: difference between rowCount() and SQL COUNT(col)

查看:247
本文介绍了PDO:rowCount()和SQL COUNT(col)之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道是否更好使用PDO类 rowCount 方法而不是SQL COUNT(col_name)

解决方案

/ div>

一个很大的区别?在 rowCount 手册上的此免责声明第页:


如果关联的PDOStatement执行的最后一条SQL语句是SELECT语句,该语句返回的行数。




如果您需要数据库中匹配的记录数,请使用 COUNT()。如果你需要数据库驱动程序认为它返回的行数/支持那个概念的数据库驱动程序中受影响的行数,那么使用PDO的 rowCount ,但是您不能保证数据将存在,这取决于底层数据库驱动程序。


I just wonder to know if is better to use PDO class rowCount method instead of SQL COUNT(col_name) to count the number of rows.

Does exist some recommended situation for each one?

解决方案

One big difference? This disclaimer on the rowCount manual page:

If the last SQL statement executed by the associated PDOStatement was a SELECT statement, some databases may return the number of rows returned by that statement. However, this behaviour is not guaranteed for all databases and should not be relied on for portable applications.

Emphasis added.

If you need the number of records in the database that match, use COUNT(). If you need the number of rows that the database driver believes it's returning to you / the number of affected rows in the database drivers that support that concept, then use PDO's rowCount, but you can't guarantee that data will be there, depending on the underlying database driver.

这篇关于PDO:rowCount()和SQL COUNT(col)之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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