Is there a way to filter the queries by table name in the zend db profiler? The documentation doesn't have anything but I don't know if I can just rely on this document completely..if you know a way, please advise..
Asked
Active
Viewed 248 times
1 Answers
1
There is currently not a way to filter the profiler based on table name, only by query type (INSERT, UPDATE, etc) or elapsed time of the query.
Here is some code you could try that may help you do what you want though, note, I have not tested it, but hopefully it can get you started.
Basically, it loops over each query that was profiled and uses preg_match to see if the query was to your table, and if not it unsets the query info and continues, if it was then it updates some stats. At the end of the foreach, $queries, should be only the queries to the table you want to profile.
<?php
$tableName = 'my_table';
/** var $profiler Zend_Db_Profiler */
$profiler = $db->getProfiler();
$queries = $profiler->getQueryProfiles();
$totalQueries = 0;
$totalTime = 0;
if ($queries !== false) {
foreach ($queries as $index => $query) {
$queryString = $query->getQuery();
$t = preg_quote($tableName);
if (!preg_match("/UPDATE .?$t.? /i", $queryString) ||
!preg_match("/INSERT INTO .?$t.?/i", $queryString) ||
!preg_match("/DELETE FROM .?$t.?/i", $queryString) ||
!preg_match("/REPLACE .*?INTO .?$t.?/i", $queryString) ||
) {
unset($queries[$index]);
continue;
}
$totalQueries++;
$totalTime += $query->getElapsedSecs();
}
}

drew010
- 68,777
- 11
- 134
- 162
-
Please check here: http://stackoverflow.com/questions/7502515/php-and-zend-db-profiler – geej Sep 21 '11 at 15:36