Skip to content

Instantly share code, notes, and snippets.

@DavidBruchmann
Forked from alexsegura/gist:9895452
Last active January 28, 2022 18:10
Show Gist options
  • Select an option

  • Save DavidBruchmann/598fc0ebe92efd6f18a7cf6bfbaf7e96 to your computer and use it in GitHub Desktop.

Select an option

Save DavidBruchmann/598fc0ebe92efd6f18a7cf6bfbaf7e96 to your computer and use it in GitHub Desktop.

Revisions

  1. DavidBruchmann revised this gist Jan 28, 2022. 1 changed file with 16 additions and 11 deletions.
    27 changes: 16 additions & 11 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,21 @@
    <?php

    $sql = '...';

    $stmt = $conn->prepare($sql);

    try {
    $stmt->execute();
    } catch (\Doctrine\DBAL\DBALException $e) {
    $previous = $e->getPrevious();
    if ($previous instanceof \Doctrine\DBAL\Driver\Mysqli\MysqliException) {
    // $errorCode contains MySQL error code (ex: 1062 for a duplicate entry)
    $errorCode = $previous->getCode();
    protected function executeQueryBuilder($queryBuilder, string $debugHeader)
    {
    $resource = null;
    try {
    $resource = $queryBuilder->execute();
    } catch (\Doctrine\DBAL\DBALException $e) {
    $previous = $e->getPrevious();
    if ($previous instanceof \Doctrine\DBAL\Driver\Mysqli\MysqliException) {
    // $errorCode contains MySQL error code (ex: 1062 for a duplicate entry)
    $errorCode = $previous->getCode();
    $errorMsg = $previous->getMessage();
    # DebuggerUtility::var_dump(['$queryBuilder' => $queryBuilder, '$errorCode' => $errorCode, '$errorMsg' => $errorMsg], $debugHeader);
    var_dump([$debugHeader, '$errorCode' => $errorCode, '$errorMsg' => $errorMsg]);
    }
    }
    return $resource;
    }
    }

  2. @alexsegura alexsegura created this gist Mar 31, 2014.
    16 changes: 16 additions & 0 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    <?php

    $sql = '...';

    $stmt = $conn->prepare($sql);

    try {
    $stmt->execute();
    } catch (\Doctrine\DBAL\DBALException $e) {
    $previous = $e->getPrevious();
    if ($previous instanceof \Doctrine\DBAL\Driver\Mysqli\MysqliException) {
    // $errorCode contains MySQL error code (ex: 1062 for a duplicate entry)
    $errorCode = $previous->getCode();
    }
    }