Doctrine 分析器无法捕获查询

发布于 2024-07-21 00:31:44 字数 1222 浏览 7 评论 0原文

我想我一定在这里遗漏了一些明显的东西。 我将 Doctrine 和 Zend Framework 设置在一起。 在 bootstrap.php 文件中,我有以下内容 - 基于使用探查器的 Doctrine 文档:

$profiler = new Doctrine_Connection_Profiler();
$conn = Doctrine_Manager::connection();
$conn->setListener($profiler);

(...)

$frontController = Zend_Controller_Front::getInstance();

(...)

$query_count = 0;
$time = 0;
echo "<table width='100%' border='1'>";
foreach ( $profiler as $event ) {
    if ($event->getName() != 'execute') {
        continue;
    }
    $query_count++;
    echo "<tr>";
    $time += $event->getElapsedSecs() ;
    echo "<td>" . $event->getName() . "</td><td>" . sprintf ( "%f" , $event->getElapsedSecs() ) . "</td>";
    echo "<td>" . $event->getQuery() . "</td>" ;
    $params = $event->getParams() ;
    if ( ! empty ( $params ) ) {
          echo "<td>";
          echo join(', ', $params);
          echo "</td>";
    }
    echo "</tr>";
}
echo "</table>";
echo "Total time: " . $time . ", query count: $query_count <br>\n ";

没有错误,探查器最后的输出仅打印:“总时间:0,查询计数:0”。

连接肯定有效,因为查询被执行 - 我有一个 SELECT 使用 Doctrine_Query::create() 及其执行方法获取一堆项目。

I think I must be missing something obvious here. I have Doctrine and Zend Framework set up together. In the bootstrap.php file I have the following - based on the Doctrine documentation for using the profiler:

$profiler = new Doctrine_Connection_Profiler();
$conn = Doctrine_Manager::connection();
$conn->setListener($profiler);

(...)

$frontController = Zend_Controller_Front::getInstance();

(...)

$query_count = 0;
$time = 0;
echo "<table width='100%' border='1'>";
foreach ( $profiler as $event ) {
    if ($event->getName() != 'execute') {
        continue;
    }
    $query_count++;
    echo "<tr>";
    $time += $event->getElapsedSecs() ;
    echo "<td>" . $event->getName() . "</td><td>" . sprintf ( "%f" , $event->getElapsedSecs() ) . "</td>";
    echo "<td>" . $event->getQuery() . "</td>" ;
    $params = $event->getParams() ;
    if ( ! empty ( $params ) ) {
          echo "<td>";
          echo join(', ', $params);
          echo "</td>";
    }
    echo "</tr>";
}
echo "</table>";
echo "Total time: " . $time . ", query count: $query_count <br>\n ";

There are no errors, the profiler output at the end only prints: "Total time: 0, query count: 0".

The connection is definitely working, as the queries get executed - I've got a SELECT fetching a bunch of items using Doctrine_Query::create() and it's execute method.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

九命猫 2024-07-28 00:31:44

有更好的方法,但这可能是一个更好的起点。

假设在引导过程中设置了连接和分析器,有几次初步尝试开发 Doctrine 资源插件,请参阅 http://www.nabble.com/RFC%3A-ZendX_Doctrine-to23454552.htmlhttp://www.nabble.com/Autoload-models-with-no-namespace-to23387744.html,你可以在控制器/操作:

http://pastie.org/475589

然后在布局或视图脚本中类似这样:

http://pastie.org/475593

There are better approaches, but this may be a better starting point.

Assuming the connection and profiler are setup during bootstrap, there are several initial attempts to develop a Doctrine resource plugin see http://www.nabble.com/RFC%3A-ZendX_Doctrine-to23454552.html and http://www.nabble.com/Autoload-models-with-no-namespace-to23387744.html, you could do something like this in a controller/action:

http://pastie.org/475589

And then something like this in a layout or view script:

http://pastie.org/475593

埋葬我深情 2024-07-28 00:31:44

在开始运行 $profiler 数组之前,它里面有什么?

What is in the $profiler array before you start running it?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文