开发者

Is there any way to output the sql generated by a propel select in symfony?

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 state开发者_JS百科ment in a situation where the sf_debug bar hasn't loaded yet, or isn't going to load at all.


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


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


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.


You'll get the generated SQL statement that way after you've build the criteria :

    $params= array();
    $resulting_sql_statement = BasePeer::createSelectSql($criteria,$params);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜