简体   繁体   中英

how to covert Symfony1.4 Doctrine:Query to Normal Mysql Query

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();

只需运行控制器的开发版本,然后从调试工具栏中复制它即可。

$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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM