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

标签 php mysql yii2

普通 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/

相关文章:

php - 如何使用dql查询doctrince 2中的sum?

mysql - 向 mysql 数据库中的所有表添加列(未知表名)

jquery - 如何删除Yii2中注册的jquery文件

php - Yii2查询结果总是返回相同的

php - IBM Watson 关系提取 "Forwarding error"(status_code 500)

php - Symfony2 : ResourceNotFoundException when using extends in a twig template

php - MySQL插入19500条速度很慢?

php - 在一行中显示两行或多行

mysql - SQL - 使用占位符检索与占位符类似的行

Yii2 authclient 不返回用户的电子邮件 ID