slam/dbal-debugstack-middleware

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

v2.0.0 2024-02-06 16:14 UTC

This package is auto-updated.

Last update: 2024-06-20 19:49:58 UTC


README

Slam\DbalDebugstackMiddleware

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
            )
    )
 */