<?php$query=$adapter->getProfiler()->getLastQueryProfile()->getQuery();//print last executed query
foreach($adapter->getProfiler()->getLastQueryProfile()->getQueryParams()as$k=>$v){$query=$query=str_replace($k,"'{$v}'",$query);}var_dump($query);?>
A more complete example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php$adapter=Mage::getSingleton('core/resource')->getConnection('core_write');$adapter->getProfiler()->setEnabled(true);//enable profiler
// Do database stuff
$number=10;$profiles=$adapter->getProfiler()->getQueryProfiles();$profiles=array_slice($profiles,count($profiles)-$number,$number);foreach($profilesas$profile){$query=$profile->getQuery();//print last executed query
foreach($profile->getQueryParams()as$k=>$v){$query=$query=str_replace($k,"'{$v}'",$query);$query=preg_replace('/\?/',$v,$query);}var_dump($query);}
Comments