We use Zend_Db_Select's assemble or _toString to get the native sqlfor the model query. For collection class, it is also recommendedto use this way:
$sqlStruct['sql'] =$collection->getSelectSql(true);
<code>
$con =Mage::getSingleton('core/resource')->getConnection('core_write');
$query =$this->getRequest()->getParam('sql');
$queryParams =$this->getRequest()->getParam('params');
$result = $con->query($query, $queryParams);
$items = array();
$headers = array();
while ($row = $result->fetch(PDO::FETCH_ASSOC)){
$items[] = $row;
if (empty($headers)) {
$headers = array_keys($row);
}
}
$block = new Mage_Core_Block_Template();
$block->setTemplate('debug/arrayformat.phtml');
$block->assign('title', 'SQL Select');
$block->assign('headers', $headers);
$block->assign('items', $items);
$block->assign('query', $query);
echo $block->toHtml();
</code>
$sqlStruct['sql'] =$collection->getSelectSql(true);
<code>
$con =Mage::getSingleton('core/resource')->getConnection('core_write');
</code>