How to make LIKE val% query condition with ActiveRecord ?

I have tried this:


return self::find()->select('id')->where(['like', 'id', $id."%", false])->asArray()->all();

This gives me error: Array to string conversion

With this:


return self::find()->select('id')->andFilterWhere(['like', 'id', $id])->asArray()->all();

I get % around both sides of the string, and I do not want that.

I red this: http://www.yiiframework.com/doc-2.0/guide-db-query-builder.html#operator-format

But I do not understand what to do… It seems complicated, or I need to read some other guide ?

Can someone help me please ? I need to make this: LIKE "1%"

Hi. I really don’t understand why do you need LIKE for id.

You can use this raw where condition:


where('CAST(id as CHAR) LIKE "1%"')

If you want to use LIKE with string column you can do this:


where('name LIKE "Mi%"')