tags:

views:

219

answers:

3

I want to output the query generated by a symfony propel select for testing purposes. Is there any way to do this? I know I can use the sf_debug bar, but sometimes I need to see the statement in a situation where the sf_debug bar hasn't loaded yet, or isn't going to load at all.

A: 

Propel Criteria objects have a toString method, so you should simply be able to echo / var_dump / log to a file the criteria object you are interested in

timmow
A: 

It also might be helpful to take a look at Day 6 of the Jobeet Tutorial, Debugging Propel generated SQL. If you're in the debug environment, the raw queries are output to the log files. Not 100% sure as I use Doctrine.

nselikoff
+1  A: 

Timmow is right that there is a Criteria::toString() method, but it's not the magic _toString() method that's automatically called when the object is referenced as a string.

If you want to see the SQL you have to explicitly call Criteria::toString().

$c = new Criteria();
// HERE: add criteria
// what's it do?
echo $c->toString(); // oh, that's what it does
dibson
Interesting - it "sorta" works - I get this output for the page I happen to be working on:Criteria: SQL (may not be complete): SELECT FROM ORDER BY ugc_question.LAST_RESPONSE_AT DESC Params:
kewpiedoll99
also, the above code snippet should say echo $c->toString(); // oh...(not $c->getString(); )
kewpiedoll99
just updated it, thanks for the extra eye
dibson