My DB type is MySQL
and i'm using PDOStatement::rowCount()
to :
- Count selected rows on
SELECT
statement - Get affected rows on
UPDATE
statement - Get deleted rows on
DELETE
statement
And i haven't any problem with that and works correctly for me.
But ,recently i've seen that :
- php.net says :
For most databases, PDOStatement::rowCount() does not return the number of rows affected by a SELECT statement. Instead, use PDO::query() to issue a SELECT COUNT(*) statement ...
- Some saying that using
COUNT(*)
in MySQL is much better and more faster instead of usingPDOStatement::rowCount()
- link - And this answer says:
rowCount() is the most misused PDO function. While it us scarcely needed once or twice per application
why ? i use this function a lot !
Whats wrong with PDOStatement::rowCount()
although it works fine for me ?
Edit : So is this an appropriate way to count rows like bellow code ,even if i don't need to fetched data ? :
$stmt -> execute();
$result = $stmt -> fetchAll();
return count($result);