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

后端 未结 19 2395
自闭症患者
自闭症患者 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:50

    getSqlQuery() does technically show the whole SQL command, but it's a lot more useful when you can see the parameters as well.

    echo $q->getSqlQuery();
    foreach ($q->getFlattenedParams() as $index => $param)
      echo "$index => $param";
    

    To make this pattern more reusable, there's a nice approach described in the comments at Raw SQL from Doctrine Query Object.

提交回复
热议问题