PDO duplicate entry error code
We get the error code (using DB unique constraint) when the resource is already created
try{
    $stmt = $conn->prepare($query);
    $stmt->execute($exec_arr);
} catch(PDOException $e) {
    if($e->getCode() == 23000){
        array_push($errors, 'Technology already exists');
    } else {
        array_push($errors, 'Database error');
    }
}
by Valeri Tandilashvili
4 years ago
PHP
1
Pro tip: use ```triple backticks around text``` to write in code fences