Afficher un message
Vieux 25/03/2008, 19h40   #3
Gilles Ganault
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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.
  Réponse avec citation
 
Page generated in 0,04423 seconds with 9 queries