0
votes

I tried to fetch some data for testing from tt_content like in the 'SELECT a single row' example here (https://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/Database/BasicCrud/Index.html#select-a-single-row):

In Controller.php:

...

use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;

...

public function listAction() {

    $uid = 4;
    $tester = GeneralUtility::makeInstance(ConnectionPool::class)
        ->getConnectionForTable('tt_content')
        ->select(
            ['uid', 'pid', 'bodytext'],
            'tt_content',
            [ 'uid' => (int)$uid ]
        )
    ->fetch()   // 1. attempt       
    ->execute();    // 2. attempt
    $this->view->assign('inet', $tester);

}

List.html:

<f:debug>{inet}</f:debug>   

Debug Output when I use ->execute() is:

Extbase Variable Dump

TRUE

Debug Output when I use ->fetch() is:

Extbase Variable Dump

FALSE
2

2 Answers

0
votes

I see your attempts, but have you tried:

->execute()->fetch()

? That should do the trick.

0
votes

So what works is e.g. this

$uid = 10;
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content');
$queryBuilder->getRestrictions()->removeAll();
$statement = $queryBuilder  
    ->select('uid', 'pid', 'header')            
    ->from('tt_content')
    ->where(
       $queryBuilder->expr()->eq('uid', $uid)
    )           
    ->execute();    
while ($row = $statement->fetchAll()) {
    $this->view->assign('inet', $row);
}