user3383675
user3383675

Reputation: 1081

How to show Query in Symfony 2.1

Situation:

$queryBuilder
    ->addSelect(  /* hardlyPredictableSelectString() */ )
    ->leftjoin (  /* hardlyPredictableJoinString()   */ )
    ->andWhere (  /* hardlyPredictableWhereString()  */ )
    ->getQuery()
    ->getResult()

I want to debug that query, but it is hardly to predictable. You know, if, else, add some text, or not... I can not simply echo $string, , so my question is: How to make something like that? $queryString=getQueryString() ?

getDQLParts(); is not good idea, because, I want to simply copy and paste that string to custom MySQL Manager.

Upvotes: 2

Views: 85

Answers (2)

kskaradzinski
kskaradzinski

Reputation: 5084

You should use symfony profiler, where You have Doctrine|Propel tab in which there is list of queries that was executed.

Upvotes: 0

Canser Yanbakan
Canser Yanbakan

Reputation: 3870

Just use getSql before getResult.

$query = $queryBuilder
    ->addSelect(  /* hardlyPredictableSelectString() */ )
    ->leftjoin (  /* hardlyPredictableJoinString()   */ )
    ->andWhere (  /* hardlyPredictableWhereString()  */ )
    ->getQuery();

echo $query->getSql();

Upvotes: 3

Related Questions