在Symfony中打印Sql查询

时间:2013-10-16 16:33:10

标签: mysql symfony

我需要找出以下的正常sql查询。你们能告诉我如何在Symfony取得成功吗? 示例:

 $r = Doctrine_Query::create()
    ->select('u.worked_hours')
     ->from('tasksComments u')
     ->where('u.tasks_id = ?', $arr_values['tasks_id'])
     ->andwhere('u.id != ?', $arr_values['id'])
     ->andwhere('u.created_at LIKE ?', $date."%");
$results1 = $r->execute();

3 个答案:

答案 0 :(得分:5)

在查询对象上,使用方法getSQL

在你的情况下:

$r = Doctrine_Query::create()
        ->select('u.worked_hours')
        ->from('tasksComments u')
        ->where('u.tasks_id = ?', $arr_values['tasks_id'])
        ->andwhere('u.id != ?', $arr_values['id'])
        ->andwhere('u.created_at LIKE ?', $date."%");

var_dump($r->getSQL()); // print the SQL query - you will need to replace the parameters in the query
var_dump($r->getParams()); // print the parameters of the query so you can easily replace the missing parameters in the query

请注意,我不知道Doctrine_Query的命名空间,但我假设您Query中有{{1}}个对象。

答案 1 :(得分:2)

将Symfony 1.4与Doctrine 1.2.3一起使用

echo $q->getSqlQuery();

答案 2 :(得分:0)

您可以通过单击数据库面板图标(工具栏的最后一部分),然后单击查询下的 [显示可运行查询] 链接,查看概要分析器工具栏中的所有已执行查询。