如何打印在 Yii php 框架中执行的最后一个查询


How do I print the last query executed in Yii php framework?

这是我的代码:

$ptoRequests = CalendarRequest::model()
                    ->with(array('intervals'))
                    ->findAll(array('order' => 't.time, t.id desc',
                'condition' => 'eventId in (5, 7, 8, 9, 10, 11) and statusId in (1,2) and userId = "' . $user->userId . '" and (intervals.enddate >= :from)',
                'params' => array('from' => date("Y-m-d"))));
                echo "<pre>"; var_dump($ptoRequests->getQuery()); echo "</pre>"; exit();

我想要实现的是打印执行的最后一个查询。getQuery() 函数向我返回一个致命错误。我该怎么办?感谢

试试这个

echo ModelClassName::model()->
getCommandBuilder()->
createFindCommand('table_name', $criteria)->text;

$criteria在哪里

$criteria= new CDbCriteria();
$criteria->condition="your query condition";
$criteria->order="t.time desc"

在此处查看 CDb 标准以供参考