Get executed query in Doctrine

I created a complex native query which is populated with quite a few parameters. When executed it didn't deliver the expected result.

To send the query to the database I use the following code:

$this->getEntityManager()
    ->getConnection()
    ->executeQuery($query, $parameter, $types)
    ->fetchAll(PDO::FETCH_BOTH);

I searched for a way to echo the generated sql (with the inserted parameters). Unfortunately it turns out, there is none. The query and the parameters are both send separatly from each other to the database and mysql itself puts them together. Therefore there is now way for Doctrine to know how the final sql will look like.

To still be able to debug the sql I found the following solution:

MySQL General query log

In short: Logging all sql statements which in the end are executed in the mysql database. To enable it, just create a new config file in /etc/mysql/conf.d/query_log.cnf and add the following content:

[mysqld]
log=/tmp/query.log # Path to your log file