如何转换Symfony 1.4 Doctrine:查询到普通的Sql查询

i have searched a lot about how to convert symfony doctrine query into normal mysql query for debugging purpose.

like i have in codeIgniter

$this->db->last_query();

it convert active records to mysql normal query for debugging purpose.

so my question is it possible to covert doctrine to normal query for debugging purpose in symfony 1.4 or symfony2, and what are the keywords.

my doctrine query is

$q_fixed = Doctrine_Query::CREATE()
                ->select('u.name')
                ->from("fields u")
                ->where("u.field_type_id=?", "1")
                ->leftJoin("u.FieldType t")
                ->leftJoin("u.FieldCategory c")
                ->groupBy("u.id");

how to convert it to normal mysql query?

your help will be appreciated.

Thank You

In symfony2 you can use getSql() on your queried object ,but for the bound parameters you will have ? in query instead of provided parameters,it will not give you the full query with the provided parameters

$query = $this->createQueryBuilder('u');
$query->select('u.name')
            ->from("fields u")
            ->where("u.field_type_id=?", "1")
            ->leftJoin("u.FieldType t")
            ->leftJoin("u.FieldCategory c")
            ->groupBy("u.id");
echo $query->getQuery()->getSql();

Just run the dev version of the controller and copy it from the debugging toolbar.

$configuration = ProjectConfiguration::getApplicationConfiguration('myapp', 'dev', true);

In Symfony 1.4 you can use getSqlQuery() method of Doctrine_Query object. It will return sql query converted from dql. Note that it may include placeholders instead of actual values of parameters, you will need to replace the ?'s with the correct values when you execute it.