# DebugStatement

> Reports the driver row count of every executed prepared statement to the request-scoped Database collector.

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

| final class | `Yii3\Debug\Db\DebugStatement` |
| --- | --- |
| Extends | [`PDOStatement`](https://www.php.net/manual/en/class.pdostatement.php) |
| Source | [`src/Db/DebugStatement.php`](https://github.com/yii3/debug/blob/main/src/Db/DebugStatement.php#L18) |

Reports the driver row count of every executed prepared statement to the request-scoped Database collector.

Yii DB 2 profiling hands observers the SQL and its context only, so the [`PDOStatement`](https://www.php.net/manual/en/class.pdostatement.php) and its `rowCount()` are
unreachable downstream. [`DebugDbProfiler::instrument()`](/docs/extensions/yii3-debug/reference/db/debugdbprofiler/index.md#method-instrument) registers this class through `PDO::ATTR_STATEMENT_CLASS`
on the live PDO instance, making every prepared statement report its own count.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) protected | Creates a statement observer that reports row counts to the Database collector. | `DebugStatement` |
| [`execute()`](#method-execute) | Executes the prepared statement and reports its row count, or `null` when the driver rejects it. | `DebugStatement` |

## Method details

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

```php
protected function __construct(Yii3\Debug\Collector\DbCollector $collector)
```

Creates a statement observer that reports row counts to the Database collector.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$collector` | [`Yii3\Debug\Collector\DbCollector`](/docs/extensions/yii3-debug/reference/collector/dbcollector/index.md) | Collector receiving the row count of every execution. |

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

```php
public function execute(array<array-key, mixed>|null $params = null): bool
```

Executes the prepared statement and reports its row count, or `null` when the driver rejects it.

A rejected statement still reports, holding `null`, so a command that never produced a count is not credited with
the count of an earlier attempt.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$params` | `array<array-key, mixed>\|null` | Values bound to the statement placeholders, if any. |

**Returns**

`bool`: `true` when the driver accepted the statement; `false` otherwise.