问题
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?
回答1:
Try
$collection->getSelect()->__toString()
See How do you display a Magento sql query as a string?
回答2:
Try out $Collection->printLogQuery(true);
this will print collection query.
Mage::log($collection->getSelect(),null,'test.log',true);
来源:https://stackoverflow.com/questions/23834183/output-raw-sql-query-from-magento-collection