Attention

TYPO3 v7 has reached its end-of-life November 30th, 2018 and is not maintained by the community anymore. Looking for a stable version? Use the version switch on the top left.

There is no further ELTS support. It is recommended that you upgrade your project and use a supported version of TYPO3.

Accessing the database

TYPO3 version 8 LTS

The TYPO3 database should always be accessed using the QueryBuilder of Doctrine. The TYPO3\CMS\Core\Database\ConnectionPool class can be used to create a \TYPO3\CMS\Core\Database\Query\QueryBuilder instance:

$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tablename');

See the Database Access API documentation for details.

For TYPO3 versions before 8 LTS

The TYPO3 database should always be accessed through the use of $GLOBALS['TYPO3_DB']. This is the instance of the DatabaseConnection class from typo3/sysext/core/Classes/Database/DatabaseConnection.php.

The same rule applies for accessing non-TYPO3 databases: they should be accessed by using a different instance of the same class. Failing this condition may corrupt the TYPO3 database or prevent access to the TYPO3 database for the rest of the script.