# DbPanel

> Renders the database queries captured by the Database collector.

[API reference](/docs/api/index.md) › [Debug](/docs/extensions/debug/reference/index.md) › [panels](/docs/extensions/debug/reference/panels/index.md) › DbPanel

| class | `yii\debug\panels\DbPanel` |
| --- | --- |
| Extends | [`yii\debug\Panel`](/docs/extensions/debug/reference/panel/index.md) » [`yii\base\Component`](/docs/api/yii/base/component/index.md) » [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| Implements | [`yii\base\ViewContextInterface`](/docs/api/yii/base/viewcontextinterface/index.md), [`yii\base\Configurable`](/docs/api/yii/base/configurable/index.md) |
| Source | [`src/panels/DbPanel.php`](https://github.com/yii2-extensions/debug/blob/main/src/panels/DbPanel.php#L27) |

Renders the database queries captured by the Database collector.

Presents the queries grid with per-query timings, the duplicate-query summary, and the EXPLAIN action that powers the
grid's inline plan toggle; data acquisition lives in [`DbCollector`](/docs/extensions/debug/reference/collectors/dbcollector/index.md).

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-actions"></span>[`$actions`](/docs/extensions/debug/reference/panel/index.md#property-actions) | `array<string, array<string, mixed>\|class-string>` | Standalone actions merged into the debug module's [`Module::$actionMap`](/docs/api/yii/base/module/index.md#property-actionMap), keyed by action ID. Default: `[]`. | [`yii\debug\Panel`](/docs/extensions/debug/reference/panel/index.md) |
| <span id="property-behaviors"></span>[`$behaviors`](/docs/api/yii/base/component/index.md#property-behaviors) read-only | `array<`[`yii\base\Behavior`](/docs/api/yii/base/behavior/index.md)`<static>>` | List of behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="property-criticalQueryThreshold"></span>`$criticalQueryThreshold` | `int\|null` | Critical-query-count threshold; when the captured query count exceeds this value the toolbar item flips to a warning state. `null` disables the check. Default: `null`. | `DbPanel` |
| <span id="property-db"></span>`$db` | `string` | Application component id of the DB connection used to run EXPLAIN queries. Default: `'db'`. | `DbPanel` |
| <span id="property-defaultFilter"></span>`$defaultFilter` | `array<string, mixed>` | Default filter applied to the queries grid as `property => value` (for example, `['type' => 'SELECT']`). Default: `[]`. | `DbPanel` |
| <span id="property-defaultOrder"></span>`$defaultOrder` | `array<string, int>` | Default sort order applied to the queries grid as `property => SORT_*` (for example, `['duration' => SORT_DESC]`). Default: `['seq' => SORT_ASC]`. | `DbPanel` |
| <span id="property-detail"></span>`$detail` read-only | `string` | Rendered detail view. | `DbPanel` |
| <span id="property-id"></span>[`$id`](/docs/extensions/debug/reference/panel/index.md#property-id) | `string` | Panel unique identifier, assigned by the container module on registration. Default: `''`. | [`yii\debug\Panel`](/docs/extensions/debug/reference/panel/index.md) |
| <span id="property-module"></span>[`$module`](/docs/extensions/debug/reference/panel/index.md#property-module) | [`yii\debug\Module`](/docs/extensions/debug/reference/module/index.md)`\|null` | Debug module owning this panel. Default: `null`. | [`yii\debug\Panel`](/docs/extensions/debug/reference/panel/index.md) |
| <span id="property-name"></span>`$name` read-only | `string` | Panel display name. | `DbPanel` |
| <span id="property-renderContext"></span>[`$renderContext`](/docs/extensions/debug/reference/panel/index.md#property-renderContext) | `PHPForge\Debug\Panel\PanelRenderContext\|null` | Prepared render context, or `null` outside a debugger request. | [`yii\debug\Panel`](/docs/extensions/debug/reference/panel/index.md) |
| <span id="property-rows"></span>`$rows` read-only | `list<PHPForge\Debug\Panel\Db\QueryRow>` | Rows in capture order. | `DbPanel` |
| <span id="property-summary"></span>`$summary` read-only | `PHPForge\Debug\Panel\Db\DbSummary` | Query metrics for the whole request. | `DbPanel` |
| <span id="property-tag"></span>[`$tag`](/docs/extensions/debug/reference/panel/index.md#property-tag) | `string` | Tag of the request whose data this panel currently exposes. Default: `''`. | [`yii\debug\Panel`](/docs/extensions/debug/reference/panel/index.md) |
| <span id="property-toolbarData"></span>[`$toolbarData`](/docs/extensions/debug/reference/panel/index.md#property-toolbarData) read-only | `array<string, mixed>` | Toolbar envelope; `[]` to skip the panel. | [`yii\debug\Panel`](/docs/extensions/debug/reference/panel/index.md) |
| <span id="property-toolbarIcon"></span>`$toolbarIcon` read-only | `string` | Toolbar icon key. | `DbPanel` |
| <span id="property-types"></span>`$types` read-only | `array<string, string>` | `type => type` map suitable for a dropdown filter. | `DbPanel` |
| <span id="property-url"></span>[`$url`](/docs/extensions/debug/reference/panel/index.md#property-url) read-only | `string` | Absolute URL to the panel detail view. | [`yii\debug\Panel`](/docs/extensions/debug/reference/panel/index.md) |
| <span id="property-viewPath"></span>[`$viewPath`](/docs/extensions/debug/reference/panel/index.md#property-viewPath) read-only | `string` | Directory the panel views resolve against. | [`yii\debug\Panel`](/docs/extensions/debug/reference/panel/index.md) |
| <span id="property-error"></span>[`$error`](/docs/extensions/debug/reference/panel/index.md#property-error) protected | `PHPForge\Debug\Storage\ExceptionSnapshot\|null` | Exception captured when the panel failed to produce or hydrate its snapshot. Default: `null`. | [`yii\debug\Panel`](/docs/extensions/debug/reference/panel/index.md) |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-__construct"></span>[`__construct()`](/docs/api/yii/base/baseobject/index.md#method-__construct) | Constructor. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__call"></span>[`__call()`](/docs/api/yii/base/component/index.md#method-__call) | Calls the named method which is not a class method. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__clone"></span>[`__clone()`](/docs/api/yii/base/component/index.md#method-__clone) | This method is called after the object is created by cloning an existing one. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__get"></span>[`__get()`](/docs/api/yii/base/component/index.md#method-__get) | Returns the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__isset"></span>[`__isset()`](/docs/api/yii/base/component/index.md#method-__isset) | Checks if a property is set, i.e. defined and not null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__set"></span>[`__set()`](/docs/api/yii/base/component/index.md#method-__set) | Sets the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__unset"></span>[`__unset()`](/docs/api/yii/base/component/index.md#method-__unset) | Sets a component property to be null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-attachBehavior"></span>[`attachBehavior()`](/docs/api/yii/base/component/index.md#method-attachBehavior) | Attaches a behavior to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-attachBehaviors"></span>[`attachBehaviors()`](/docs/api/yii/base/component/index.md#method-attachBehaviors) | Attaches a list of behaviors to the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-behaviors"></span>[`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) | Returns a list of behaviors that this component should behave as. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-canGetProperty"></span>[`canGetProperty()`](/docs/api/yii/base/component/index.md#method-canGetProperty) | Returns a value indicating whether a property can be read. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-canSetProperty"></span>[`canSetProperty()`](/docs/api/yii/base/component/index.md#method-canSetProperty) | Returns a value indicating whether a property can be set. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-capture"></span>[`capture()`](/docs/extensions/debug/reference/panel/index.md#method-capture) | Captures the panel payload for the current request. | [`yii\debug\Panel`](/docs/extensions/debug/reference/panel/index.md) |
| <span id="method-className"></span>[`className()`](/docs/api/yii/base/baseobject/index.md#method-className) static | Returns the fully qualified name of this class. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-detachBehavior"></span>[`detachBehavior()`](/docs/api/yii/base/component/index.md#method-detachBehavior) | Detaches a behavior from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-detachBehaviors"></span>[`detachBehaviors()`](/docs/api/yii/base/component/index.md#method-detachBehaviors) | Detaches all behaviors from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-ensureBehaviors"></span>[`ensureBehaviors()`](/docs/api/yii/base/component/index.md#method-ensureBehaviors) | Makes sure that the behaviors declared in [`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) are attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getBehavior"></span>[`getBehavior()`](/docs/api/yii/base/component/index.md#method-getBehavior) | Returns the named behavior object. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getBehaviors"></span>[`getBehaviors()`](/docs/api/yii/base/component/index.md#method-getBehaviors) | Returns all behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`getDb()`](#method-getDb) | Returns the DB connection used by the panel for EXPLAIN queries. | `DbPanel` |
| [`getDetail()`](#method-getDetail) | Renders the detail view with the queries grid, the EXPLAIN toggle, and the duplicate-query summary. | `DbPanel` |
| <span id="method-getError"></span>[`getError()`](/docs/extensions/debug/reference/panel/index.md#method-getError) | Returns the exception captured while collecting the panel payload, if any. | [`yii\debug\Panel`](/docs/extensions/debug/reference/panel/index.md) |
| [`getName()`](#method-getName) | Returns the panel display name from the shared title enum. | `DbPanel` |
| <span id="method-getRenderContext"></span>[`getRenderContext()`](/docs/extensions/debug/reference/panel/index.md#method-getRenderContext) | Returns the framework-neutral render context for the active debugger request, when one has been prepared. | [`yii\debug\Panel`](/docs/extensions/debug/reference/panel/index.md) |
| [`getRows()`](#method-getRows) | Returns the executed statements as typed rows hydrated from the stored snapshot. | `DbPanel` |
| [`getSummary()`](#method-getSummary) | Returns the request-wide query metrics, computed once per hydrated snapshot and reused by every consumer. | `DbPanel` |
| <span id="method-getToolbarData"></span>[`getToolbarData()`](/docs/extensions/debug/reference/panel/index.md#method-getToolbarData) | Returns the toolbar envelope wrapping the panel's icon, items, and URL. | [`yii\debug\Panel`](/docs/extensions/debug/reference/panel/index.md) |
| [`getToolbarIcon()`](#method-getToolbarIcon) | Returns the icon key from the shared panel icon enum. | `DbPanel` |
| <span id="method-getTraceLine"></span>[`getTraceLine()`](/docs/extensions/debug/reference/panel/index.md#method-getTraceLine) | Builds a trace line for the toolbar through the shared [`Trace`](https://github.com/php-forge/debug-core/blob/b70459f033a1d7a1c5edf7951029aad2061986dd/src/Helper/Trace.php) renderer, applying [`Module::$tracePathMappings`](/docs/extensions/debug/reference/module/index.md#property-tracePathMappings) and the configured [`Module::$traceLine`](/docs/extensions/debug/reference/module/index.md#property-traceLine) template (or callable). | [`yii\debug\Panel`](/docs/extensions/debug/reference/panel/index.md) |
| [`getTypes()`](#method-getTypes) | Returns the distinct SQL statement types captured for the request, keyed and valued by the same uppercase token. | `DbPanel` |
| <span id="method-getUrl"></span>[`getUrl()`](/docs/extensions/debug/reference/panel/index.md#method-getUrl) | Returns the URL pointing to this panel's detail view for the current request tag. | [`yii\debug\Panel`](/docs/extensions/debug/reference/panel/index.md) |
| <span id="method-getViewPath"></span>[`getViewPath()`](/docs/extensions/debug/reference/panel/index.md#method-getViewPath) | Returns the directory under which the panel's relative views resolve. | [`yii\debug\Panel`](/docs/extensions/debug/reference/panel/index.md) |
| <span id="method-hasContent"></span>[`hasContent()`](/docs/extensions/debug/reference/panel/index.md#method-hasContent) | Returns whether the panel captured content for the loaded request. | [`yii\debug\Panel`](/docs/extensions/debug/reference/panel/index.md) |
| <span id="method-hasError"></span>[`hasError()`](/docs/extensions/debug/reference/panel/index.md#method-hasError) | Returns `true` when [`setError()`](/docs/extensions/debug/reference/panel/index.md#method-setError) captured an exception during panel capture or hydration. | [`yii\debug\Panel`](/docs/extensions/debug/reference/panel/index.md) |
| <span id="method-hasEventHandlers"></span>[`hasEventHandlers()`](/docs/api/yii/base/component/index.md#method-hasEventHandlers) | Returns a value indicating whether there is any handler attached to the named event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasMethod"></span>[`hasMethod()`](/docs/api/yii/base/component/index.md#method-hasMethod) | Returns a value indicating whether a method is defined. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasProperty"></span>[`hasProperty()`](/docs/api/yii/base/component/index.md#method-hasProperty) | Returns a value indicating whether a property is defined for this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`hydrate()`](#method-hydrate) | Decodes the captured payload into the typed query snapshot and discards the memoized summary. | `DbPanel` |
| [`init()`](#method-init) | Registers the `db-explain` action. | `DbPanel` |
| [`isEnabled()`](#method-isEnabled) | Returns whether the panel can run: requires both a resolvable DB connection and the parent enable check. | `DbPanel` |
| [`isQueryCountCritical()`](#method-isQueryCountCritical) | Returns whether the given query count exceeds [`$criticalQueryThreshold`](/docs/extensions/debug/reference/panels/dbpanel/index.md#property-criticalQueryThreshold). | `DbPanel` |
| <span id="method-isVisible"></span>[`isVisible()`](/docs/extensions/debug/reference/panel/index.md#method-isVisible) | Returns whether the panel should appear in the toolbar and sidebar navigation. | [`yii\debug\Panel`](/docs/extensions/debug/reference/panel/index.md) |
| <span id="method-moduleBound"></span>[`moduleBound()`](/docs/extensions/debug/reference/panel/index.md#method-moduleBound) | Completes module-dependent wiring after the container module binds [`$id`](/docs/extensions/debug/reference/panel/index.md#property-id) and [`$module`](/docs/extensions/debug/reference/panel/index.md#property-module). | [`yii\debug\Panel`](/docs/extensions/debug/reference/panel/index.md) |
| <span id="method-off"></span>[`off()`](/docs/api/yii/base/component/index.md#method-off) | Detaches an existing event handler from this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-on"></span>[`on()`](/docs/api/yii/base/component/index.md#method-on) | Attaches an event handler to an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-setError"></span>[`setError()`](/docs/extensions/debug/reference/panel/index.md#method-setError) | Records an exception thrown during capture or hydration so [`LogTarget`](/docs/extensions/debug/reference/logtarget/index.md) can surface it in the UI. | [`yii\debug\Panel`](/docs/extensions/debug/reference/panel/index.md) |
| <span id="method-setRenderContext"></span>[`setRenderContext()`](/docs/extensions/debug/reference/panel/index.md#method-setRenderContext) | Installs the framework-neutral render context prepared for this panel by the debugger action. | [`yii\debug\Panel`](/docs/extensions/debug/reference/panel/index.md) |
| <span id="method-trigger"></span>[`trigger()`](/docs/api/yii/base/component/index.md#method-trigger) | Triggers an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`getModels()`](#method-getModels) protected | Returns the typed query rows consumed by the queries grid. | `DbPanel` |
| [`getToolbarItems()`](#method-getToolbarItems) protected | Builds the query-count toolbar chip, with a warning when the count is critical or callers are excessive. | `DbPanel` |
| [`getTotalQueryTime()`](#method-getTotalQueryTime) protected | Returns the sum of every captured query's duration. | `DbPanel` |
| [`hasExplain()`](#method-hasExplain) protected | Returns whether the DB connection's driver supports the EXPLAIN action (currently `mysql`, `sqlite`, `pgsql`). | `DbPanel` |

## Method details

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

```php
public function getDb(): yii\db\Connection
```

Returns the DB connection used by the panel for EXPLAIN queries.

**Returns**

[`yii\db\Connection`](/docs/api/yii/db/connection/index.md): Connection the EXPLAIN action runs against.

**Throws**

- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): when the configured component id does not resolve to a [`Connection`](/docs/api/yii/db/connection/index.md).

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

```php
public function getDetail(): string
```

Renders the detail view with the queries grid, the EXPLAIN toggle, and the duplicate-query summary.

**Returns**

`string`: Rendered detail view.

**Throws**

- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): when the DB connection cannot be resolved.

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

```php
public function getName(): string
```

Returns the panel display name from the shared title enum.

**Returns**

`string`: Panel display name.

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

```php
public function getRows(): list<PHPForge\Debug\Panel\Db\QueryRow>
```

Returns the executed statements as typed rows hydrated from the stored snapshot.

**Returns**

`list<PHPForge\Debug\Panel\Db\QueryRow>`: Rows in capture order.

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

```php
public function getSummary(): PHPForge\Debug\Panel\Db\DbSummary
```

Returns the request-wide query metrics, computed once per hydrated snapshot and reused by every consumer.

**Returns**

`PHPForge\Debug\Panel\Db\DbSummary`: Query metrics for the whole request.

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

```php
public function getToolbarIcon(): string
```

Returns the icon key from the shared panel icon enum.

**Returns**

`string`: Toolbar icon key.

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

```php
public function getTypes(): array<string, string>
```

Returns the distinct SQL statement types captured for the request, keyed and valued by the same uppercase token.

**Returns**

`array<string, string>`: `type => type` map suitable for a dropdown filter.

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

```php
public function hydrate(array<string, mixed> $payload): void
```

Decodes the captured payload into the typed query snapshot and discards the memoized summary.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$payload` | `array<string, mixed>` | Captured panel payload. |

**Throws**

- `PHPForge\Debug\Storage\HydrationException`: when the payload does not match the snapshot schema.

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

```php
public function init(): void
```

Registers the `db-explain` action.

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

```php
public function isEnabled(): bool
```

Returns whether the panel can run: requires both a resolvable DB connection and the parent enable check.

**Returns**

`bool`: `true` when a DB connection resolves and the parent check passes; `false` otherwise.

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

```php
public function isQueryCountCritical(int $count): bool
```

Returns whether the given query count exceeds [`$criticalQueryThreshold`](/docs/extensions/debug/reference/panels/dbpanel/index.md#property-criticalQueryThreshold).

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$count` | `int` | Query count to test. |

**Returns**

`bool`: `true` when the count exceeds the threshold; `false` otherwise.

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

```php
protected function getModels(): list<PHPForge\Debug\Panel\Db\QueryRow>
```

Returns the typed query rows consumed by the queries grid.

**Returns**

`list<PHPForge\Debug\Panel\Db\QueryRow>`: Rows in capture order, suitable for [`ArrayDataProvider`](/docs/api/yii/data/arraydataprovider/index.md).

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

```php
protected function getToolbarItems(): array<int, array<string, mixed>>
```

Builds the query-count toolbar chip, with a warning when the count is critical or callers are excessive.

**Returns**

`array<int, array<string, mixed>>`: Toolbar items, or `[]` when no queries were captured.

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

```php
protected function getTotalQueryTime(): float
```

Returns the sum of every captured query's duration.

**Returns**

`float`: Total query time, in milliseconds.

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

```php
protected function hasExplain(): bool
```

Returns whether the DB connection's driver supports the EXPLAIN action (currently `mysql`, `sqlite`, `pgsql`).

**Returns**

`bool`: `true` when the driver supports EXPLAIN; `false` otherwise.

**Throws**

- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): when the DB connection cannot be resolved.