Doctrine - How to print out the real sql, not just the prepared statement?

后端 未结 19 2478
自闭症患者
自闭症患者 2020-11-30 18:59

We\'re using Doctrine, a PHP ORM. I am creating a query like this:

$q = Doctrine_Query::create()->select(\'id\')->from(\'MyTable\');

19条回答
  •  没有蜡笔的小新
    2020-11-30 19:44

    I wrote a simple logger, which can log query with inserted parameters. Installation:

    composer require cmyker/doctrine-sql-logger:dev-master
    

    Usage:

    $connection = $this->getEntityManager()->getConnection(); 
    $logger = new \Cmyker\DoctrineSqlLogger\Logger($connection);
    $connection->getConfiguration()->setSQLLogger($logger);
    //some query here
    echo $logger->lastQuery;
    

提交回复
热议问题