Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

php pdo check if record exists before insert

$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.';
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #php #pdo #check #record #exists #insert
ADD COMMENT
Topic
Name
9+1 =