【问题标题】:doctrine dbal count number of querys executed学说 dbal count 执行的查询数
【发布时间】:2013-05-31 07:13:06
【问题描述】:

我已经构建了自己的 mvc 框架,并且正在使用 Doctrine DBAL 2.3 作为数据库层。 目前我正在为这个框架开发一个分析器。 我想在分析器中添加的一件事是在当前页面上执行的查询数。

我的问题是:我可以从 Doctrine 获取查询的数量吗? 是的?我怎样才能做到这一点? 不?有没有一种方法可以构建与 Doctrine 一起使用的自定义功能并成功?

希望有人能回答我的问题,谢谢。

【问题讨论】:

    标签: php model-view-controller count doctrine dbal


    【解决方案1】:

    Doctrine 2 提供了一个简单的日志接口,即\Doctrine\DBAL\Logging\SQLLogger()

    https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Logging/SQLLogger.php

    $config = new Doctrine\ORM\Configuration ();
    // ... config stuff
    $config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
    $connectionParams = array(
            'dbname' => 'example',
            'user' => 'example',
            'password' => 'example',
            'host' => 'localhost',
            'driver' => 'pdo_mysql');
    //make the connection through an Array of params ($connectionParams)
    $em = EntityManager::create($connectionParams, $config);
    

    【讨论】:

    • 抱歉这么久才回答,我要感谢您的回答,它对我帮助很大!谢谢!
    猜你喜欢
    • 2016-08-25
    • 1970-01-01
    • 2017-11-24
    • 1970-01-01
    • 1970-01-01
    • 2015-02-28
    • 2011-09-11
    • 2017-05-03
    • 1970-01-01
    相关资源
    最近更新 更多