1

I am new to Typo3. I am using 6.1 version of it.

I need to display the MySQL query generated from the query object. Please let me know how can I do that?

Below is the code snippet that is in my repository class.

$query = $this->createQuery();
$query->getQuerySettings()->setRespectStoragePage(false);
$query->matching(
    $query->equals('id',intval($id))
);

return $query->execute();

I need to display the MySQL query before executing and returning the result of the query.

Please let me know how can I do that.

Thanks in advance.

cweiske
  • 30,033
  • 14
  • 133
  • 194
Krish Damani
  • 185
  • 2
  • 14

2 Answers2

3

in extbase its very hard to display the last query.

you might try the normal TYPO3 way, but you have to execute the query before you can do that:

$GLOBALS['TYPO3_DB']->store_lastBuiltQuery = 1;

//query

// the complete SQL-Statement
echo $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery;

Another way is to go into the buildQuery(array $sql) just before the return statement and add this snippet:

if (in_array("your_table_name", $sql['tables'])) {
    var_dump($statement);
    print_r($statement);
}

You can find the buildQuery method here:

TYPO3 ver.: 4.x: typo3/sysext/extbase/Classes/Persistence/Storage/Typo3DbBackend.php
TYPO3 ver.: 6.x: typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php

Edit: A very good method is to just misspell the column name. For example: Column is called test, call it testsdffq. The query will fail and it will show you the whole query.

Xatenev
  • 6,383
  • 3
  • 18
  • 42
  • I am not getting how to implement this. Can you please elaborate? – Krish Damani Sep 11 '14 at 05:24
  • Okay I tried to implement the second way. You meant to implement it in the core library files and then remove them after completed up with the debugging right? This is what I did. – Krish Damani Sep 11 '14 at 06:26
  • @KrishDamani Yea exactly :). You have to put it into the core because the query is built there. You have to get the raw query before anything else happens :). – Xatenev Sep 11 '14 at 07:08
0

May be this will help.

Make sure the following is set in localconf.php:

$TYPO3_CONF_VARS['SYS']['sqlDebug'] = '1';   
$TYPO3_CONF_VARS['FE']['debug'] = '1';  

try

$res = $GLOBALS['TYPO3_DB']->SELECTquery('*', 'tx_xmluploader_xml_import_tree', 'xml_import_id='.$xml_import_id);
t3lib_div::debug($res);

Result will be output of the query in the frontend. You can then execute it in MySQL for debugging.

Naincy
  • 2,953
  • 1
  • 12
  • 21