Issue Bug Closed

#78129Statement::rowCount not reliable for SELECT queries

Oliver Hader 10/02/16, 23:41 updated 01/28/20, 15:52

Description

see https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Driver/Statement.php#L127

… taken from the PHPdoc comment:
> Returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement
> executed by the corresponding object.
>
> If the last SQL statement executed by the associated Statement object 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.

In particular rowCount() on valid SELECT statements for SQLite as DBMS returns 0 when fetch() would retrieve existing records. Thus, using rowCount() should be avoided and replaced by proper COUNT statements instead – if required at all.

Reviews 1