PHP高级工程师|全栈工程师|WX: Aben_Ring

phalcon常用语法

打印SQL

//在config/service.php中注册服务    
$di->set(
    'profiler',
    function () {
        return new \Phalcon\Db\Profiler();
    },
    true
);


//在controller中输出如下代码
$profiles = $this->di->get('profiler')->getProfiles();
//遍历输出
foreach ($profiles as $profile) {
    echo "SQL语句: ", $profile->getSQLStatement(), "<br/>";
    //echo "开始时间: ", $profile->getInitialTime(), "\n";
    //echo "结束时间: ", $profile->getFinalTime(), "\n";
    //echo "消耗时间: ", $profile->getTotalElapsedSeconds(), "\n";
}
//最后语句
//echo $this->di->get('profiler')->getLastProfile()->getSQLStatement();
die;

 

posted @ 2018-08-15 14:50  懒牛拉车  阅读(162)  评论(0编辑  收藏  举报