Afficher un message
Vieux 25/03/2008, 15h14   #2
Guillaume
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Finding if a record exists?

Gilles Ganault a écrit :
> I need to check if a phone number exists in a database. Using the
> following SQL statement, what is the right way to code this in PHP?
>
> $dbh = new PDO("sqlite:test.sqlite");
> $sql = "SELECT 1 AS number FROM phones WHERE phones_tel='123'";
> $row = $dbh->query($sql)->fetch();


I would say:
$numrows = $dbh->query($sql)->numrows();
I suppose numrows exists as well as fetch, then it should be lighter not
to fetch the data but only ask how many were returned.
Then, $numrows is either a PDO error or an integer which you can check.

Regards,

--
Guillaume
  Réponse avec citation
 
Page generated in 0,05001 seconds with 9 queries