Search code examples
typo3typo3-10.x

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


Is there a way to execute plain SQL in typo3 version 10? How can I do this?

// 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)) {
  // ...
}

EDIT

The simple script SELECT * FROM tt_content is only a placeholder. I want do some special migrations or some special requests for my statistic page.


Solution

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