mpyw/unique-violation-detector

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

v1.2.0 2025-03-05 03:19 UTC

This package is auto-updated.

Last update: 2025-03-05 03:31:05 UTC


README

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

Installing

composer require mpyw/unique-violation-detector

Requirements

Package Version
PHP ^8.2

Note

Older versions have outdated dependency requirements. If you cannot prepare the latest environment, please refer to past releases.

Supported PDO Drivers

Database Driver Auto-Discoverable
MySQL pdo_mysql
PostgreSQL pdo_pgsql
SQLite pdo_sqlite
SQLServer pdo_sqlsrv
SQLServer pdo_odbc
SQLServer pdo_dblib
Oracle pdo_oci

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);