Tuesday, August 9, 2011

How to get SQL Query as a string in magento?

If you are using collections, There are two ways of getting SQL from the collection of Magento.
1. Echoing Query String.
	
/** If $collection is your collection**/
$collection->printlogquery(true);
/** Don't forget to write true in param**/
But by this method you cannot assign the query you get echoed to some variable.

2. Getting the query String
$query=$collection->getSelectSql(true);
echo $query;

No comments:

Post a Comment