0

In Typo3 version 6.1, I have written some custom queries in My extension Repository

for example in file Mytest/Classes/Domain/Repository/MytestRepository.php

class MytestRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {
 public function myFunction(){

        $sql = 'SELECT * FROM some_table ';

        $sqlResult = $GLOBALS['TYPO3_DB']->sql_query($sql);
        while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($sqlResult)) {
                $rowone = $row['rowone'];
        }
 }
}

And calling that function in controller

$test = $this->MytestRepository->myFunction();

But the issue here is, I am getting error

Fatal error: Call to a member function fetch_assoc() on a non-object in /home/src/typo3_src-6.1.1/typo3/sysext/core/Classes/Database/DatabaseConnection.php on line 1029 

Anybody have the solution ? Thanks in advance.

1 Answers1

2

You can execute custom queries like this:

$query = $this->createQuery();
$query->statement('SELECT * FROM some_table');
$result = $query->execute();

If you don't want to get objects as a result from the query, which i assume looking at your while loop, you can set the following line before executing the query:

$query->getQuerySettings()->setReturnRawQueryResult(TRUE);

With setReturnRawQueryResult you get a plain array as a result.

Shufla
  • 872
  • 4
  • 10
  • Thank you very much. The problem was not from while loop. In previous function I had similar custom query for truncate table. There by mistak I had added query->getQuerySettings()->setReturnRawQueryResult(TRUE); – Ganybhat-Satvam Software Jun 12 '13 at 12:35
  • Can you then please mark the answer properly that it solved your problem? – Shufla Jun 12 '13 at 12:58
  • For TYPO33 7.x you can write return $query->execute(TRUE); because setReturnRawQueryResult is depricated. – Vishal Tanna Jan 01 '16 at 07:35