2

有没有办法在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只是一个占位符。我想对我的统计页面做一些特殊的迁移或一些特殊的请求。

4

3 回答 3

4
$connection = GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionForTable('tt_content');
$resultSet = $connection->query('SELECT * FROM tt_content')->execute();
于 2020-05-11T17:22:29.130 回答
0

适用于我的 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();

感谢创意

于 2020-06-09T08:34:38.440 回答
-1

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

使用 TYPO3Connection的示例:

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

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

于 2020-05-11T15:52:29.963 回答