Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I view the parameters in a query?

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 thing I achieved is having the raw query using:

$qb->getQuery()->getSQL();

The problem is that instead of parameters I see the holders (?). I found some solutions on the web but they are for 1.3 and 1.4, nothing for Symfony-2.

Ideas? Thanks!

like image 921
guyaloni Avatar asked Jun 27 '12 12:06

guyaloni


People also ask

How do you show parameters in Excel?

On the Data tab, in the Connections group, click Properties. In the Connection Properties dialog box, click the Definition tab, and then click Parameters. In the Parameters dialog box, in the Parameter name list, click the parameter that you want to change.

What is an example of a parameter query?

Query Parameter Example For example, in `https://www.google.com/search?q=abstract%20api`, we have a standard Google search, with the user input `abstract%20api` being passed as a variable via the query parameter `q=`. We can pass multiple variables with the `&` symbol separating parameters, forming a query string.

How do I view an Access query?

To view the SQL code for an Access query, open the query in query design view. Then click the “View” drop-down button in the “Results” button group on the “Design” tab of the “Query Tools” contextual tab in the Ribbon. From the drop-down menu of choices that appears, select the “SQL View” command.


1 Answers

You can access the parameters used by the placeholders using $query->getParameters(), so you could debug your query using:

$query = $qb->getQuery();
print_r(array(
    'sql'        => $query->getSQL(),
    'parameters' => $query->getParameters(),
));
like image 160
AdrienBrault Avatar answered Oct 24 '22 11:10

AdrienBrault