在 null 上调用成员函数 exec_SELECTquery()

Call to a member function exec_SELECTquery() on null

我将我的网站升级到 TYPO3 9。5.x 但升级后我的一些自定义扩展出现错误。

(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

因此我去查看了文件,这是我在第499行找到的:

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

不再有 TYPO3_DB,他们正在使用一种新方法。检查这个主题,它可能会有帮助:https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Database/Migration/Index.html

更新。这实际上取决于变量中存储的内容。作为一个基本示例,您可以尝试:

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();

安装扩展 TYPO3_DB compatibility layer for TYPO3 v9.x/typo3db_legacy 为 TYPO3 9+ 版本提供 $GLOBALS['TYPO3_DB']