第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

yii2.0獲取到最后一條執(zhí)行的sql怎么看

yii2.0獲取到最后一條執(zhí)行的sql怎么看

Yii
POPMUISE 2019-02-12 09:25:42
yii2.0獲取到最后一條執(zhí)行的sql怎么看
查看完整描述

1 回答

?
智慧大石

TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超3個贊

這個有很多種方法

1. yii有提供一個 getRawSql方法  比如說一個查詢

1

2

3

4

$query = User::find();

$query->select(['username','age'])->where(['id'=>1)->one();

 

echo $query->createCommand()->getRawSql();//輸出sql語句

2.可開啟yii2的debug模塊,這個功能很強(qiáng)大,在里面可以查到當(dāng)前頁面所有的sql信息,具體配置方法自行百度,網(wǎng)上太多這個配置了

3.查找Yii源碼   隨便找個模型調(diào)用原生的方法 比如 User::updateAll 方法,通過編輯器定位到updateAll方法的源碼 你會發(fā)現(xiàn)下面一段代碼

1

2

3

4

5

6

7

public static function updateAll($attributes, $condition = '', $params = [])

{

   $command = static::getDb()->createCommand();

   $command->update(static::tableName(), $attributes, $condition, $params);

 

   return $command->execute();

}

繼續(xù)定位execute方法

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

public function execute()

{

   $sql = $this->getSql();

   $rawSql = $this->getRawSql();

 

   Yii::info($rawSql, __METHOD__);

   if ($sql == '') {

      return 0;

   }

 

   $this->prepare(false);

        $token = $rawSql;

        try {

            Yii::beginProfile($token, __METHOD__);

 

            $this->pdoStatement->execute();

            $n = $this->pdoStatement->rowCount();

 

            Yii::endProfile($token, __METHOD__);

 

            $this->refreshTableSchema();

 

            return $n;

        } catch (\Exception $e) {

            Yii::endProfile($token, __METHOD__);

            throw $this->db->getSchema()->convertException($e, $rawSql);

        }

    }

方法里 $rawSql就是最原生要執(zhí)行的sql拉,在這里打斷點(diǎn)輸出就ok



 

 


查看完整回答
反對 回復(fù) 2019-02-16
  • 1 回答
  • 0 關(guān)注
  • 696 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號