Home > PHP Framework > YII > How to print sql in yii2

How to print sql in yii2

藏色散人
Release: 2020-07-21 10:40:34
Original
3477 people have browsed it

yii2 method of printing sql: first query the structure through the statement "Article::find()->joinWith('articleClass');"; then call the createComment and getSql methods; finally print it out through "var_dump" That’s it.

How to print sql in yii2

##YII2.0 printing sql statement method

//1、查询结构  
$record = Article::find()->joinWith('articleClass');  
//2、复制一下查询语句  
$query = clone $record;  
//3、调用createComment()和getSql()方法  
$sql = $query->createCommand()->getSql();  
//4、打印出来  
var_dump($sql);die();
Copy after login

Recommended: "

yii tutorial"

The above is the detailed content of How to print sql in yii2. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template