How do I view the parameters in a query?

后端 未结 5 1389
遇见更好的自我
遇见更好的自我 2021-02-08 04:09

In order to debug my code I would like to see the explicit sql query that is executed.

I create the query with createQueryBuilder, and the most explicit thi

5条回答
  •  渐次进展
    2021-02-08 04:20

    I had to build a requete union (impossible with DQL or QueryBuilder) with 5 query already built with the QueryBuilder. So I reuse these queries but I had a problem using getParameters() function because it give the parameter in same order you have given it. One of the advantages when you use the query builder is you can create a query in order yhou want but when you retrieve parameters, you may retrieve it in messy. to avoid this i have built the following function:

        $getSqlWithParams = \Closure::bind(function(){
            return [$this->getSql(), $this->processParameterMappings($this->_parserResult->getParameterMappings())];
        }, null, Query::class);
    

    now when you want retrieve sql and the sorted parameters you do :

    $getSqlWithParams()->call($query)
    

    Don't forget use \Doctrine\ORM\Query statement. And voilà!

提交回复
热议问题