Home  >  Article  >  Backend Development  >  yii2.0的curd

yii2.0的curd

WBOY
WBOYOriginal
2016-06-06 20:17:201369browse

yii2.0中有没有一个像tp中的getLastSql()方法去查询执行后的sql语句

回复内容:

yii2.0中有没有一个像tp中的getLastSql()方法去查询执行后的sql语句

<code>echo (new \yii\db\Query)->from('users')
    ->where(['name'=>'moca'])
    ->createCommand()
    ->rawSql; // 同getRawSql()</code>

输出

<code>SELECT * FROM `users` WHERE `name`='moca'
</code>

yii-db-command

这个不清楚,不过可以使用debug模式,查看运行的状态,和执行的SQL信息


在 web/index.php

<code>defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'test');</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn