# DebugPdoStatement

> Records the row count produced by every executed prepared statement.

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

| class | `yii\debug\db\DebugPdoStatement` |
| --- | --- |
| Extends | [`PDOStatement`](https://www.php.net/manual/en/class.pdostatement.php) |
| Source | [`src/db/DebugPdoStatement.php`](https://github.com/yii2-extensions/debug/blob/main/src/db/DebugPdoStatement.php#L21) |

Records the row count produced by every executed prepared statement.

The Yii profiler captures each query's SQL and timing but discards the [`PDOStatement`](https://www.php.net/manual/en/class.pdostatement.php), so the row count is
unrecoverable downstream. This subclass hooks [`PDOStatement::execute()`](https://www.php.net/manual/en/class.pdostatement.php) to read `rowCount()` right after
execution and append it to a request-scoped list in execution order.

Registered by [`DbCollector`](/docs/extensions/debug/reference/collectors/dbcollector/index.md) via [`PDO::ATTR_STATEMENT_CLASS`](https://www.php.net/manual/en/class.pdo.php) on the collector-bound DB
connection, so every prepared statement returned by the underlying PDO instance is one of these.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-rowCounts"></span>`$rowCounts` static | `list<int\|null>` | Row count per executed statement, appended in execution order; `null` marks a statement whose execution threw, so later statements keep their sequence position. Default: `[]`. | `DebugPdoStatement` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) protected | Visibility is `protected` because [`PDO::ATTR_STATEMENT_CLASS`](https://www.php.net/manual/en/class.pdo.php) requires it; callers must not instantiate the class outside of the PDO factory. | `DebugPdoStatement` |
| [`execute()`](#method-execute) | Executes the prepared statement and records its row count in [`DebugPdoStatement::$rowCounts`](/docs/extensions/debug/reference/db/debugpdostatement/index.md#property-rowCounts). | `DebugPdoStatement` |

## Method details

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

```php
protected function __construct()
```

Visibility is `protected` because [`PDO::ATTR_STATEMENT_CLASS`](https://www.php.net/manual/en/class.pdo.php) requires it; callers must not instantiate the
class outside of the PDO factory.

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

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

Executes the prepared statement and records its row count in [`DebugPdoStatement::$rowCounts`](/docs/extensions/debug/reference/db/debugpdostatement/index.md#property-rowCounts).

A statement that throws still occupies a slot, holding `null`, because the Database panel aligns the list with
the trailing captured timings: skipping the failed statement would shift every later row count onto the wrong
query.

**Parameters**

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

**Returns**

`bool`: `true` on success, `false` on failure.

**Throws**

- [`PDOException`](https://www.php.net/manual/en/class.pdoexception.php): When the driver rejects the statement in `PDO::ERRMODE_EXCEPTION` mode.