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.
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.