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.
Accessing the database
The TYPO3 database should always be accessed using the Query
of
Doctrine. The ConnectionPool class should be
injected via constructor injection and can then
be used to create a QueryBuilder instance:
<?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 chapter for more details.