dongpang1898 2011-09-19 16:23
浏览 58

php zend db profiler按表名过滤

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..

  • 写回答

1条回答 默认 最新

  • dtoka218420 2011-09-19 17:21
    关注

    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();
            }
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line