如何在 typo3 版本 10 ($GLOBALS['TYPO3_DB']->sql_query()) 中执行纯 SQL?

How to execute plain SQL in typo3 version 10 ($GLOBALS['TYPO3_DB']->sql_query())?

有没有办法在 typo3 版本 10 中执行纯 SQL?我该怎么做?

// in previous versions you could do the following
$sql = 'SELECT * FROM tt_content;';
$GLOBALS['TYPO3_DB']->sql_query($sql);
while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
  // ...
}

编辑

简单脚本SELECT * FROM tt_content只是一个占位符。我想对我的统计页面做一些特殊的迁移或一些特殊的请求。

不再需要在 TYPO3 中执行原始 SQL,因为基于 Doctrine 的 DBAL API 非常强大,基本上可以让你做任何事情。

你的例子using the TYPO3 Connection class:

$result = GeneralUtility::makeInstance(ConnectionPool::class)
    ->getConnectionForTable('tt_content')
    ->select(['*'], 'tt_content');

foreach ($result as $row) {
    // ...
}

$connection = GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionForTable('tt_content');
$resultSet = $connection->query('SELECT * FROM tt_content')->execute();

适用于我的 TYPO3 9。

    // looky-looky at 20200609: https://www.strangebuzz.com/en/snippets/running-raw-sql-queries-with-doctrine
    /** @var Connection $connection */
    $connection = GeneralUtility::makeInstance(ConnectionPool::class)
        ->getConnectionForTable(self::TABLENAME);
    /** @var DriverStatement $statement */
    $statement = $connection->prepare($sql);
    $statement->execute();

感谢Idea