码迷,mamicode.com
首页 > 数据库 > 详细

yii 输出当前的sql语句

时间:2015-11-24 16:05:28      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:

<?php

namespace app\controllers;

use yii\web\Controller;
use yii\data\Pagination;
use app\models\Country;

class CountryController extends Controller{
    
    public function actionIndex(){
        $query = Country::find();

        $pagination = new Pagination([
            ‘defaultPageSize‘ => 7,
            ‘totalCount‘ => $query->count(),
        ]);        
        $countries = $query->orderBy(‘name‘)
            ->offset($pagination->offset)
            ->limit($pagination->limit)
            ->all();
        $commandQuery = clone $query;
        echo $commandQuery->createCommand()->getRawSql();//SELECT * FROM `country` ORDER BY `name` LIMIT 7
        return $this->render(‘index‘, [
            ‘countries‘ => $countries,
            ‘pagination‘ => $pagination,
        ]);
    }
}

 

yii 输出当前的sql语句

标签:

原文地址:http://www.cnblogs.com/719907411hl/p/4991866.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!