从TYPO3_DB迁移

时间:2019-06-27 16:37:13

标签: php typo3-9.x

我将网站迁移到TYPO3 9x。但是迁移后,我在以下扩展名之一中遇到了错误:

Call to a member function sql_num_rows() on null在这一行:

if($GLOBALS['TYPO3_DB']->sql_num_rows($res)){
    while($CATEGORY = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)){
        $uids[] = $CATEGORY['uid'];
    }
}

根据此链接,我将需要更改代码结构:

https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Database/Migration/Index.html#result-set-iteration

所以我更改了这样的代码:

if($statement = $queryBuilder->execute()){
while ($category = $statement->fetch()) {
    $uids[] = $category['uid'];
}
}

但是我仍然收到错误Call to a member function execute() on null

请如何更改我的代码以使其起作用?

1 个答案:

答案 0 :(得分:0)

在您的问题中,您没有提及此代码的准备工作。也许你错过了什么。
这里是扩展的示例:

$connection = GeneralUtility::makeInstance(ConnectionPool::class);
$queryBuilder = $connection->getQueryBuilderForTable('tx_myext_domain_model_myrecords');
$queryBuilder->select('uid', 'titel')
            ->from('tx_myext_domain_model_myrecords')
            ->where(
                $queryBuilder->expr()->orX(
                    $queryBuilder->expr()->like('title',   $queryBuilder->createNamedParameter($searchWord)),
                    $queryBuilder->expr()->like('content', $queryBuilder->createNamedParameter($searchWord))
                ));

只有这样

$statement = $queryBuilder->execute();

此代码可能与TYPO3 8的代码略有不同。