---
title: "Deprecation: #96972 - Deprecate QueryBuilder::execute()"
manual: "TYPO3 Core Changelog"
version: "main"
permalink: "https://docs.typo3.org/permalink/changelog:deprecation-96972"
source: "Changelog/12.0/Deprecation-96972-DeprecateQueryBuilderexecute.rst"
typo3-version: "12.0"
typo3-major: 12
type: "deprecation"
issue: 96972
forge: "https://forge.typo3.org/issues/96972"
tags: ["Database", "NotScanned", "ext:core"]
rendered: "2026-09-17T12:41:04+00:00"
---

# Deprecation: #96972 - Deprecate QueryBuilder::execute() {#deprecation-96972-deprecate-querybuilder-execute}

See [forge#96972](https://forge.typo3.org/issues/96972)

## Description {#description}

`doctrine/dbal` deprecated the union return-type method `QueryBuilder->execute()` in favour
of single return-typed `QueryBuilder->executeQuery()` and `QueryBuilder->executeStatement()`
in `doctrine/dbal v3.1.x`. This makes it more obvious which return type is expected and further helps
static code analyzer tools like `phpstan` to recognize return types properly. TYPO3 already provides a
facade class around the `doctrine/dbal` `QueryBuilder`, which has been changed to provide the new
methods in the Core facade class with a corresponding backport.

Thus `QueryBuilder->execute()` is marked as deprecated in TYPO3 v12 and will be removed in v13 to
encourage extension developers to use the cleaner methods and decrease issues with static code analysers.

## Impact {#impact}

The method `execute()` is also used for Extbase query execution and as Upgrade Wizard method, thus
the extension scanner is not configured to scan for this method to avoid a lot of noisy weak matches.

`QueryBuilder->execute()` will trigger a PHP `E_USER_DEPRECATED` error when called.

## Affected Installations {#affected-installations}

In general, instances with extensions that uses the deprecated `QueryBuilder->execute()` method.

## Migration {#migration}

Extensions should use the proper methods `QueryBuilder->executeQuery()` and `QueryBuilder->executeStatement()`
instead of the generic `QueryBuilder->execute()`. Through the backport to TYPO3 v11 extensions can change to deprecation
less code but keep supporting two major Core version at the same time.

-   `QueryBuilder::executeStatement()`: use this for INSERT, DELETE or UPDATE queries (expecting `int` as return value).
-   `QueryBuilder::executeQuery()`: use this for SELECT and COUNT queries (expecting ResultSet as return value).

As a thumb rule you can say that queries which expects a result set should use `QueryBuilder::executeQuery()`.
Queries which return the number of affected rows should use `QueryBuilder::executeStatement()`.

For example, following select query:

```php
$rows = $queryBuilder
  ->select(...)
  ->from(...)
  ->execute()
  ->fetchAllAssociative();
```

should be replaced with:

```php
$rows = $queryBuilder
  ->select(...)
  ->from(...)
  ->executeQuery()
  ->fetchAllAssociative();
```

As another example, given delete query:

```php
$deletedRows = $queryBuilder
  ->delete(...)
  ->execute();
```

should be replaced with:

```php
$deletedRows = $queryBuilder
  ->delete(...)
  ->executeStatement();
```
