php – Yii2: Delete multiple records from a database in one go. (removal according to the parameters from the array)

Question:

Is there any functionality opposite to batchInsert() ?

Wherever the parameters are passed.

('table_name', [ column_name1 , ... , column_name3], [params1[], ..., params3[]])

And work on deleting rows from the database if in the specified columns

column_name1 => value  == params1[i]
..................................
column_name3 => value  == params3[i]

Or how can this problem be solved using a single access to the database?

Answer:

Try this code, need to use DAO

  Yii::$app->db->createCommand()
       ->delete(ModelClass::tableName(), ['key' => $value], $params = [])
       ->execute();

http://www.yiiframework.com/doc-2.0/guide-db-dao.html

Scroll to Top