jonny
(Jonny)
January 7, 2014, 3:26am
1
Hi,
What’s the correct way to use multiple where clauses and pass parameters to the conditions. I’m looking at the docs, which are good, but I’m clearly doing something wrong. As I’m getting the error in the title.
->where([
's.id' => ':id',
'j.live' => 1]
)
->addParams([':id'=>$id])
Thanks
Jonny
jonny
(Jonny)
January 7, 2014, 3:42am
2
Ended up doing this:
->where('s.id = :id')
->addParams([':id'=>$id])
->andwhere('j.live=:live', [':live' => 1])
If that is ok?
Also: Here at the bottom of this section: https://github.com/yiisoft/yii2/blob/master/docs/guide/query-builder.md#specifying-select-conditions
It says:
But the code example below goes on to use "addwhere"
CeBe
January 7, 2014, 4:22am
3
Your way is correct but to fix the first version, just do it this way:
->where([
's.id' => $id,
'j.live' => 1]
)
No need to use params when you use the array variant.
this was a typo. I just fixed it.