twigmac twigmac - 10 months ago 85
PHP Question

Propel: Get Raw SQL from Query object?

How do I get the raw SQL statement from a query object in Propel? I need this for debugging purposes.

For example: I would like to have a function as in

$rawSql = new BookQuery::create()->filterById(25)->getRawSql();

Does something like this exist?


Yes; you're after the toString method from the Criteria parent class:

$rawSql = (new BookQuery)::create()->filterById(25)->toString();

As @jakerella says, the specific values you use for filtering will be bound by the database engine, rather than Propel, and so you'll see the structure of the query but not exactly what will be executed. If you want to see that, then you can check your database query logs, if they're enabled.