Call to a member function exec_SELECTquery() on null

Viewed 1638

I upgraded my website to TYPO3 9.5.x but I get errors with somes custom extensions after upgrade.

(1/1) Error : Call to a member function exec_SELECTquery() on null` in /var/www/example.com/typo3conf/ext/customext/pi1/class.tx_extension_pi1.php line 499

I therefore went to see in the file, and this is what I find in line 499:

$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($select, $table, $where, $groupBy, $orderBy, $limit);`
2 Answers

There's no TYPO3_DB anymore, they're using a new approach. Check this topic, it might be helpful: https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Database/Migration/Index.html

UPD. It really depends on what is stored in the variables. As a basic example you can try:

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;

$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
$queryBuilder->select($select)
->from($table)
->where($where)
->groupBy($groupBy)
->orderBy($orderBy)
->setMaxResults($limit);

// (optional) You can see the built SQL and try to adapt if needed
//  \TYPO3\CMS\Core\Utility\DebugUtility::debug($queryBuilder->getSQL());

$res = $queryBuilder->execute();
Related