mpyw/unique-violation-detector

检测从PDOException中抛出的主键/唯一键或约束违规错误。

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

This package is auto-updated.

Last update: 2024-09-13 08:05:30 UTC


README

PDOException检测主键/唯一键或约束违规错误。

安装

composer require mpyw/unique-violation-detector

需求

支持的PDO驱动程序

用法

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