title: Deleting record if it exists in php/PDO
body: <p>I have some code that deletes a record from a MySQL database, but I get the success message even if the record does not exist. I have searched for ways of producing a message if the record does not exist but cannot find one that works with my code.</p>
  
  <p>My code is:</p>
  
  <pre><code>try {
      $dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);
      /*** echo a message saying we have connected ***/
      //echo 'Connected to database&lt;br /&gt;';
      $dbh-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
      $sql = "DELETE FROM ukgh WHERE telephone = :telephone";
      $stmt = $dbh-&gt;prepare($sql);
      $stmt-&gt;bindParam(':telephone', $telephone, PDO::PARAM_STR);   
      $stmt-&gt;execute(); 
  
      /*** close the database connection ***/
      $dbh = null;
  }
  catch(PDOException $e) {
      echo $e-&gt;getMessage();
  }
  // once processing is complete
  // show success message
  echo 'Success - The record for ' . $telephone . ' has been deleted.';
  ?&gt;
  </code></pre>
  
  <p>Note to Fred-ii- The answer you referred to is correct, but the terminology in the question I asked was different. I asked how to ensure the RECORD I was deleting existed. I did not ask how to check if a row exists, and would never have thought to search for anything about an existing ROW when I was looking for an existing RECORD. To some experts like yourself a row may be the same as a record, but I and possibly other less enlightened people like me have never heard a record called a row.  Best wishes, Tog</p>