Doctrine - How to print out the real sql, not just the prepared statement?

后端 未结 19 2472
自闭症患者
自闭症患者 2020-11-30 18:59

We\'re using Doctrine, a PHP ORM. I am creating a query like this:

$q = Doctrine_Query::create()->select(\'id\')->from(\'MyTable\');

19条回答
  •  醉酒成梦
    2020-11-30 19:47

    You can check the query executed by your app if you log all the queries in mysql:

    http://dev.mysql.com/doc/refman/5.1/en/query-log.html

    there will be more queries not only the one that you are looking for but you can grep for it.

    but usually ->getSql(); works

    Edit:

    to view all the mysql queries I use

    sudo vim /etc/mysql/my.cnf 
    

    and add those 2 lines:

    general_log = on
    general_log_file = /tmp/mysql.log
    

    and restart mysql

提交回复
热议问题