While developing a Typo3 extension you might send queries to your database table to read or write some data.
Typo3 supports different comfortable functions to ease up the query definition. Due to this, there is no point in your code where you have the full sql statement available to debug this. So to find out what a query looks like that was finally submitted to the database, you could either check the database itself or use a Typo3 internal feature to retrieve the last submitted query.

Typo3 provides the class t3lib_DB to phrase your SQL query. The used instance of this class could also be configured to store the last database query executed to later access and check it.
The following code example shows how to use this feature in your extension code:


// activate query protocol
$GLOBALS['TYPO3_DB']->store_lastBuiltQuery = TRUE;

// execute database query
$resultSet = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query(...);

// printout the captured query
// Note: you should use log capabilitites instead of print_r() in production!
print_r($GLOBALS['TYPO3_DB']->debug_lastBuiltQuery);

Typo3: Output of the Last Executed SQL Query in an Extension

Post navigation


Leave a Reply