Re: Finding if a record exists?
On Tue, 25 Mar 2008 14:14:58 +0100, Guillaume
<ggrason@NOSPAM.gmail.com.INVALID> wrote:
>I would say:
>$numrows = $dbh->query($sql)->numrows();
Thanks for the tip, but numrows() doesn't exist in PDO, and roCount()
isn't reliable when used with SELECT:
"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 with the same
predicates as your intended SELECT statement, then use
PDOStatement->fetchColumn() to retrieve the number of rows that will
be returned. Your application can then perform the correct action."
So I guess the right way is to use "SELECT count(*).
Thanks.
|