Attention
TYPO3 v10 has reached end-of-life as of April 30th 2023 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 v10 here: TYPO3 ELTS.
Various Tips and Tricks¶
Use
Find usagesofPhpStormfor examples! The source code of the core is a great way to learn how specific methods of the API are used. InPhpStormit is extremely helpful to right click on a single method and list all method usages withFind usages. This is especially handy to quickly see usage examples of complex methods likejoin()from theQueryBuilder.INSERT,UPDATEandDELETEstatements are often easier to read and write using theConnectionobject instead of theQueryBuilder.SELECT DISTINCT aFieldis not supported but can be substituted with a->groupBy('aField').getSQL()andexecute()can be used after each other during development to simplify debugging:$queryBuilder ->select('uid') ->from('tt_content') ->where( $queryBuilder->expr()->eq('bodytext', $queryBuilder->createNamedParameter('klaus')) ); debug($queryBuilder->getSql()); $statement = $queryBuilder->execute();
In contrast to the old API based on
$GLOBALS['TYPO3_DB'],doctrine-dbalwill throw exceptions if something goes wrong when callingexecute(). The exception type is a\Doctrine\DBAL\DBALExceptionwhich can be caught and transferred to a better error message if the application has to expect query errors. Note this is not good habit and often indicates an architectural flaw of the application at a different layer.count()query types using theQueryBuildertypically call->fetchColumn(0)to receive the count value. Thecount()method ofConnectionobject does that automatically and returns the count value result directly.