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

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

    More clear solution:

     /**
     * Get string query 
     * 
     * @param Doctrine_Query $query
     * @return string
     */
    public function getDqlWithParams(Doctrine_Query $query){
        $vals = $query->getFlattenedParams();
        $sql = $query->getDql();
        $sql = str_replace('?', '%s', $sql);
        return vsprintf($sql, $vals);
    }
    

提交回复
热议问题