YII基础二

YII多表关联查询

->select("{{%relation_detail}}.name")
->from("{{%user}}")
->leftJoin("{{%relation_user}}", "{{%user}}.user_id = {{%relation_user}}.id")
->leftJoin("{{%relation_detail}}", "{{%relation_user}}.user_name = {{%relation_detail}}.user_name")
->all();

yii2打印上次执行的sql语句

$driver=Driver::find();
$driver->.........//执行的操作
$sql=$driver ->createCommand()->getRawSql(); 
var_dump($sql);die;

猜你喜欢

转载自www.cnblogs.com/gaocy/p/9750571.html
yii