«

Yii2 查询条件使用总结

时间:2024-2-28 16:09     作者:韩俊     分类: PHP


Yii2 查询条件使用总结。

Model::find()

//第一种:等于和模糊

->Where(['=', 'status',10])
->andWhere(['like', 'title','yii'])
# WHERE (`status` = 10) AND (`title` LIKE '%yii%')

//第二种:并列等于

->Where(['and', 'id=1', 'name=2'])
# WHERE id=1 AND name=2

//第三种:并列或,并列与

->Where(['and', 'type=1', ['or', 'id=1', 'id=2']])
# WHERE type=1 AND (id=1 OR id=2)

//第四种:并列或模糊

->Where(['or like','name',['哈哈','苦苦']]);
# WHERE `name` LIKE '%哈哈%' OR `name` LIKE '%苦苦%'

//第五种:并列模糊,并列与

->Where(['or',['like','name','哈哈'],['like','title','苦苦']])
# WHERE (`status`=1) AND ((`name` LIKE '%哈哈%') OR (`title` LIKE '%苦苦%'))

//第六种:小于等于

->Where(['<=', 'id', 8])
# WHERE id<=8

//第七种:between

->andWhere(['between','updated_at','2023-2-6 15:23:10', '2024-2-6 15:23:10'])
#where updated_at between ('2023-2-6 15:23:10', '2024-2-6 15:23:10')

标签: php php教程

热门推荐