Try the following
// make sure PDO is set to throw exceptions
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $dbh->prepare($qry2);
foreach ($newvalues as $obj) {
try {
$stmt->execute(array(
':LINE_NAME' => $obj->LINE_NAME,
':MODEL_NAME' => $obj->MODEL_NAME,
':PROD_NO' => $obj->PROD_NO,
':LOT_SIZE_IN' => $obj->LOT_SIZE_IN,
':START_SERIAL' => $obj->START_SERIAL,
':SERIAL_NO_LOW' => $obj->SERIAL_NO_LOW,
':SERIAL_NO_UP' => $obj->SERIAL_NO_UP,
':PROD_DATE' => $obj->PROD_DATE
));
} catch (PDOException $e) {
$errorInfo = $stmt->errorInfo();
if ($errorInfo[1] != 1062) {
throw $e;
}
}
}
I'm not entirely sure that 1062
is the error code to be checking for. In the past, I've used 1586
to detect unique constraint violations. Trial and error will discover the right value to check.
You were also using $stmt->errorInfo
as a property instead of the method $stmt->errorInfo()
.