I have a MySQL table which has a field for email addresses which is defined as unique. For this example, let\'s say that all my form does is allow a user to insert their em
A simpler way that works for me is to check the error code against an array of duplicate status codes.That way you dont have to worry what PDO returns.
$MYSQL_DUPLICATE_CODES=array(1062,23000);
try {
$prep->execute($values);
// do other things if successfully inserted
} catch (PDOException $e) {
if (in_array($e->getCode(),$MYSQL_DUPLICATE_CODES)) {
// duplicate entry, do something else
} else {
// an error other than duplicate entry occurred
}
}
Thanks! :-)