# DebugDbProfiler

> Adapts Yii DB 2 command profiling to request-scoped Database observations without recording parameters or arguments.

[API reference](/docs/api/index.md) › [Yii3 Debug](/docs/extensions/yii3-debug/reference/index.md) › [Db](/docs/extensions/yii3-debug/reference/db/index.md) › DebugDbProfiler

| final class | `Yii3\Debug\Db\DebugDbProfiler` |
| --- | --- |
| Implements | `Yiisoft\Db\Profiler\ProfilerInterface` |
| Source | [`src/Db/DebugDbProfiler.php`](https://github.com/yii3/debug/blob/main/src/Db/DebugDbProfiler.php#L28) |

Adapts Yii DB 2 command profiling to request-scoped Database observations without recording parameters or arguments.

Connection and command timings are also forwarded to the application profiler when configured.
Only the native method category is forwarded; parameter arrays and exception objects are not copied.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Creates a DB profiler that records statements while optionally forwarding spans. | `DebugDbProfiler` |
| [`begin()`](#method-begin) | Opens a profiling block for one statement. | `DebugDbProfiler` |
| [`end()`](#method-end) | Closes the profiling block opened for the same token and records the statement. | `DebugDbProfiler` |
| [`instrument()`](#method-instrument) | Registers this profiler on the connection and enables driver-reported row counts. | `DebugDbProfiler` |

## Method details

### __construct() <span id="method-__construct"></span>

```php
public function __construct(Yii3\Debug\Collector\DbCollector $collector, Yiisoft\Profiler\ProfilerInterface|null $profiler = null)
```

Creates a DB profiler that records statements while optionally forwarding spans.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$collector` | [`Yii3\Debug\Collector\DbCollector`](/docs/extensions/yii3-debug/reference/collector/dbcollector/index.md) | Collector receiving the captured statements and failures. |
| `$profiler` | `Yiisoft\Profiler\ProfilerInterface\|null` | Application profiler to keep feeding, or `null` when the debugger is the only observer. |

### begin() <span id="method-begin"></span>

```php
public function begin(string $token, array<array-key, mixed>|Yiisoft\Db\Profiler\ContextInterface $context = []): void
```

Opens a profiling block for one statement.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$token` | `string` | Statement text identifying the block. |
| `$context` | `array<array-key, mixed>\|Yiisoft\Db\Profiler\ContextInterface` | Profiling context supplied by the connection. |

### end() <span id="method-end"></span>

```php
public function end(string $token, array<array-key, mixed>|Yiisoft\Db\Profiler\ContextInterface $context = []): void
```

Closes the profiling block opened for the same token and records the statement.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$token` | `string` | Statement text identifying the block. |
| `$context` | `array<array-key, mixed>\|Yiisoft\Db\Profiler\ContextInterface` | Profiling context supplied by the connection. |

### instrument() <span id="method-instrument"></span>

```php
public function instrument(Yiisoft\Db\Driver\Pdo\PdoConnectionInterface&Yiisoft\Db\Profiler\ProfilerAwareInterface $connection): void
```

Registers this profiler on the connection and enables driver-reported row counts.

Statements are instrumented through `PDO::ATTR_STATEMENT_CLASS`, installed on the live PDO instance immediately
when the connection is already open and again on every open, including the opens that precede the captured
request. A connection wired with `setProfiler()` alone is still captured, but its Rows column stays empty.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$connection` | `Yiisoft\Db\Driver\Pdo\PdoConnectionInterface&Yiisoft\Db\Profiler\ProfilerAwareInterface` | Development connection to observe. |