Announcement

Collapse
No announcement yet.

Generating raw SQL using queryBuilder and queryComposer

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Generating raw SQL using queryBuilder and queryComposer

    I need to see raw SQL in many scenarios. It recently became known to me that the query composer can turn a query builder object into raw SQL.

    PHP Code:
    $selectQuery $entityManager->getQueryBuilder()
        ->
    select(['column1''column2''someExpression'])
        ->
    from('SomeTable')    
        ->
    order('column1''DESC')
        ->
    limit(010)
        ->
    build();

    $sql 
    $entityManager->getQueryComposer()->compose($selectQuery); 

    You can then print the SQL statement to the log:
    PHP Code:
    $GLOBALS["log"]->debug("sql",[$sql]); 
Working...
X