I'm having trouble understanding an exception bubbling issue.
My code (stripped down to its essence):
Code: Select all
my_func($org_id, $dbh) {
try {
$queryiefe = "insert into another_table (id, error_type_id) values (?, 1)";
$q = $dbh->prepare($queryiefe);
$q->bindParam(1, $org_id);
$q->execute();
}
catch(PDOException $pe) {
if( $pe->getCode() != 23000)
{
echo "Error insert event_feed_error\n";
}
else {
echo "Ignoring duplicate key error for $org_id\n";
}
}
}
$dbh = new PDO($dbconn, DB_USER, DB_PASSWORD);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$querysef = "select * from driving_table";
$q = $dbh->query($querysef);
$q->setFetchMode(PDO::FETCH_ASSOC);
while ($rowsef = $q->fetch()) {
my_func($org_id, $dbh);
}
After 49 loop iterations, the fetch() statement comes up empty. At that point, I get the following message, pointing at the while(fetch()) line:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '3822-1' for key 'PRIMARY''
This is the error (23000) that I'm catching in my_func(). The key value 3822-1 indicates that it is the last of the four unique key violations.
Why is this bubbling up to main?
Thanks!