gpt4 book ai didi

php - 在 yii2 中编写具有多个 where 条件的查询

转载 作者:行者123 更新时间:2023-11-29 07:14:56 25 4
gpt4 key购买 nike

普通 php 中的查询是

$p = "SELECT * FROM followusers WHERE (follower='$followed1 and
followed='$follower1') or (follower='$follower1' and
followed='$followed1')"

我在 yii2 中编写的查询是

 $y = Followusers::find()->where(['follower' => $userid ] and
['followed' => $conid])->orwhere(['followed' => $userid ] and
['follower' => $conid])-> all();

但我没有得到 yii2 中查询所需的结果

最佳答案

试试这个方法:

Followusers::find()->where(['follower' => $userid])    
->andWhere(['followed' => $conid])
->orwhere(['AND',
['followed' => $userid],
['follower' => $conid]
])
-> all();

关于php - 在 yii2 中编写具有多个 where 条件的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38281591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com