I have the following bit of code:
try {
$sth = $db->prepare("INSERT INTO provider_specialties (id,specialtyID) VALUES (?,?)");
$sth->execute(array($provID,$specialtyID));
}
catch(PDOExecption $e) { echo "PDO Error: ".$e->getMessage(); exit; }
When ok data is being inserted, it works fine. But when it's fed data that would cause a foreign key exception, instead of catching the exception, it crashes the script with a fatal error. I do have the
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION)
set to make sure it throws exceptions. I've seen a few others post about similar try/catch issues here, but none matching this one.
Aucun commentaire:
Enregistrer un commentaire