Afficher un message
Vieux 25/03/2008, 14h49   #1
Gilles Ganault
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Finding if a record exists?

Hello

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();

//1.
if(!$row['number'])
print "Not found";
else
print "Found";

//2.
if(count($row))
print "Found";
else
print "Not found";

//3.
if(!$row[0])
print "Not found";
else
print "Found";

$dbh = null;

Thank you.
  Réponse avec citation
 
Page generated in 0,05601 seconds with 9 queries