slam/dbal-debugstack-middleware

Doctrine\DBAL middleware for precise query debugging (DebugStack replacement)

v2.1.0 2024-09-25 07:05 UTC

This package is auto-updated.

Last update: 2024-11-21 22:38:41 UTC


README

Latest Stable Version Downloads Integrate

Doctrine\DBAL middleware for precise query debugging (DebugStack replacement). Compared to the default logging middleware, this one:

  1. Tracks the query's execution time
  2. Doesn't handle exceptions
  3. Doesn't track disconnections

Installation

composer require slam/dbal-debugstack-middleware

Usage

use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\ParameterType;
use Slam\DbalDebugstackMiddleware\DebugStack;
use Slam\DbalDebugstackMiddleware\Middleware;

$debugStack = new DebugStack();

$conn = DriverManager::getConnection(
    $connectionParams,
    (new Configuration)->setMiddlewares([
        new Middleware($debugStack)
    ])
);

$result = $conn->executeQuery(
    'SELECT * FROM users WHERE active = :active',
    ['active' => true],
    ['active' => ParameterType::BOOLEAN],
);

print_r($debugStack->getQueries());

/*
 * Output:
 *
    Array
    (
        [0] => Slam\DbalDebugstackMiddleware\Query Object
            (
                [sql] => SELECT * FROM users WHERE active = :active
                [params] => Array
                    (
                        [active] => true
                    )
                [types] => Array
                    (
                        [active] => 5
                    )
                [executionMs] => 72.05312
            )
    )
 */