Accessing the database

The TYPO3 database should always be accessed using the QueryBuilder of Doctrine. The ConnectionPool class should be injected via constructor injection and can then be used to create a QueryBuilder instance:



namespace MyVendor\MyExtension\Domain\Repository;

use TYPO3\CMS\Core\Database\ConnectionPool;

final class MyTableRepository
    private const TABLE_NAME = 'tx_myextension_domain_model_mytable';

    public function __construct(
        private readonly ConnectionPool $connectionPool,
    ) {}

    public function findSomething()
        // Get a query builder for a table
        $queryBuilder = $this->connectionPool

See the Database chapter for more details.