---
title: "Accessing the database"
manual: "TYPO3 Explained"
version: "11.5"
permalink: "https://docs.typo3.org/permalink/t3coreapi:cgl-database-access@11.5"
source: "CodingGuidelines/CodingBestPractices/AccessingTheDatabase.rst"
rendered: "2026-10-21T15:30:00+00:00"
---

> [!WARNING]
> **Attention**
>
> TYPO3 v11 has reached end-of-life as of October 31th 2024 and
> is no longer being maintained. Use the version switcher on the top
> left of this page to select documentation for a supported version of TYPO3.
>
> Need more time before upgrading?
> You can purchase Extended Long Term Support (ELTS) for TYPO3 v11 here:
> [TYPO3 ELTS](https://typo3.com/services/extended-support-elts).

# Accessing the database {#cgl-database-access}

The TYPO3 database should always be accessed using the `QueryBuilder` of
Doctrine. The [ConnectionPool](https://docs.typo3.org/permalink/t3coreapi:database-connection-pool@11.5) class should be
injected via [constructor injection](https://docs.typo3.org/permalink/t3coreapi:constructor-injection@11.5) and can then
be used to create a [QueryBuilder](https://docs.typo3.org/permalink/t3coreapi:database-query-builder@11.5) instance:

**EXT:my_extension/Classes/Domain/Repository/MyTableRepository.php**

```php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\Domain\Repository;

use TYPO3\CMS\Core\Database\ConnectionPool;

final class MyTableRepository
{
    private const TABLE_NAME = 'tx_myextension_domain_model_mytable';

    private ConnectionPool $connectionPool;

    public function __construct(ConnectionPool $connectionPool) {
        $this->connectionPool = $connectionPool;
    }

    public function findSomething()
    {
        // Get a query builder for a table
        $queryBuilder = $this->connectionPool
            ->getQueryBuilderForTable(self::TABLE_NAME);
    }
}

```

See the [Database](https://docs.typo3.org/permalink/t3coreapi:database@11.5) chapter for more details.
