Output raw SQL query from Magento collection
Asked Answered
M

2

5

I have the following collection and want to view the raw SQL within my IDE Xdebug tool -

$collection = Mage::getResourceModel('rp/organisation_collection')
                ->searchByPostcodeLastname($postcode, Slastname)
                ->addFieldToSelect(array('organisation_id'))
                ->setPageSize(1);

$qry = $organisation->load()->getSelect();

This while does show the Varien object doesn't seem to give me the raw SQL for me to check - can someone confirm what I am doing wrong?

Meldameldoh answered 23/5, 2014 at 16:25 Comment(0)
C
10

Try

$collection->getSelect()->__toString()

See How do you display a Magento sql query as a string?

Craze answered 23/5, 2014 at 16:30 Comment(1)
The issue with this approach is that limits and filters are not pritnedChaos
A
-1

Try out $Collection->printLogQuery(true); this will print collection query.

Mage::log($collection->getSelect(),null,'test.log',true);
Adabelle answered 28/5, 2015 at 17:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.