E
E
EvgMul2015-11-09 18:13:25
MySQL
EvgMul, 2015-11-09 18:13:25

How to make a query to the database in Yii2?

Hello. you need to make the following query using Yii2

SELECT * FROM table WHERE (id= '$id') AND (blocked = 1 or blocked = null )

I got the code like this:
$model2 = Table::find()->where(['id' => $model->id])->andWhere(['blocked' => null])->orWhere(['blocked' => '1'])->all();

But it doesn't work correctly. Please tell me how to make it right.
Thanks in advance to all who respond.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Talgat Baltasov, 2015-11-10
@EvgMul

->where(['and',['id'=>$id],['or','blocked=1','blocked=null']])

M
Maxim Grechushnikov, 2015-11-09
@maxyc_webber

where('id=:id and (blocked=1 or blocked is null)')->bind(':id', $id')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question