mpyw/unique-violation-detector

Detect primary/unique key or constraint violation errors from PDOException.

v1.1.0 2021-11-27 04:07 UTC

This package is auto-updated.

Last update: 2024-11-13 08:33:26 UTC


README

Detect primary/unique key or constraint violation errors from PDOException.

Installing

composer require mpyw/unique-violation-detector

Requirements

Supported PDO Drivers

Usage

use Mpyw\UniqueViolationDetector\MySQLDetector;

// Explicitly instantiate a detector
$violated = (new MySQLDetector())->uniqueConstraintViolated($exception);
use Mpyw\UniqueViolationDetector\DetectorDiscoverer;

// Discover a detector from a PDO instance
// (Not available for pdo_odbc and pdo_dblib)
$violated = (new DetectorDiscoverer())
    ->discover($pdo)
    ->uniqueConstraintViolated($exception);