PHP PDO Compruebe si existe un registro antes de insertar
$sql = $dbh->prepare("SELECT COUNT(*) AS `total` FROM directory WHERE telephone = :phone");
$sql->execute(array(':phone' => $telephone));
$result = $sql->fetchObject();
if ($result->total > 0)
{
echo 'The telephone number: ' . $telephone. ' is already in the database<br />';
}
else
{
echo 'No rows matched the query.';
}
Borma