按照http://framework.zend.com/manual/en/zend.db.profiler.html上的示例代码,我设置了 Zend Framework 应用程序的数据库分析。
应用程序.ini:
db.profiler.enabled = true
查看助手:
$totalTime = $profiler->getTotalElapsedSecs();
$queryCount = $profiler->getTotalNumQueries();
$longestTime = 0;
$longestQuery = null;
foreach ($profiler->getQueryProfiles() as $query) {
if ($query->getElapsedSecs() > $longestTime) {
$longestTime = $query->getElapsedSecs();
$longestQuery = $query->getQuery();
}
}
echo 'Executed ' . $queryCount . ' queries in ' . $totalTime . ' seconds' . "\n";
echo 'Average query length: ' . $totalTime / $queryCount . ' seconds' . "\n";
echo 'Queries per second: ' . $queryCount / $totalTime . "\n";
echo 'Longest query length: ' . $longestTime . "\n";
echo "Longest query: \n" . $longestQuery . "\n";
它适用于选择/插入/更新/删除查询。
但是我无论如何都找不到让探查器显示启动实际数据库连接所花费的时间,尽管文档暗示它确实记录了这一点。
我怀疑 Zend_Db 根本没有使用分析器记录与数据库的连接。
有谁知道这里发生了什么?
我正在使用 Oracle 数据库适配器和 ZF 1.10.1
更新:
我知道可以过滤分析器输出,这样它只会显示某些查询类型,例如选择/插入/更新。似乎还有一个选项可以仅过滤连接记录:
$profiler->setFilterQueryType(Zend_Db_Profiler::CONNECT);
但是,我的问题是分析器没有记录以 开头的连接,所以这个过滤器什么都不做。
我知道这是一个事实,因为如果我打印分析器对象,它包含许多不同查询的数据 - 但没有连接查询的数据:
print_r($profiler);
//输出 Zend_Db_Profiler 对象 ( [_queryProfiles:protected] => 数组 ( [0] => Zend_Db_Profiler_Query 对象 ( [_query:protected] => 从 table1 中选择 * [_queryType:protected] => 32 [_startedMicrotime:protected] => 1268104035.3465 [_endedMicrotime:protected] => 1268104035.3855 [_boundParams:protected] => 数组 ( ) ) [1] => Zend_Db_Profiler_Query 对象 ( [_query:protected] => 从 table2 中选择 * [_queryType:protected] => 32 [_startedMicrotime:protected] => 1268104035.3882 [_endedMicrotime:protected] => 1268104035.419 [_boundParams:protected] => 数组 ( ) ) ) [_启用:受保护] => 1 [_filterElapsedSecs:protected] => [_filterTypes:protected] => )
我是不是做错了什么——或者连接日志还没有添加到 Zend Framework 中?