search

Home  >  Q&A  >  body text

php - Yii2 uses a sql statement to batch update instead of looping inserts. How to achieve this?

Yii implements the following batch insertion method. If it is batch update, is there the same implementation method in Yii2?


Yii::$app->db
    ->createCommand()
    ->batchInsert($table, $columns, $rows)
    ->execute();

Batch update is a method of using a SQL statement to implement batch updates instead of cyclic updates, e.g:

UPDATE order
    SET field = CASE order_no
        WHEN 1 THEN 'value'
        WHEN 2 THEN 'value'
        WHEN 3 THEN 'value'
    END
WHERE order_no IN (1,2,3)
漂亮男人漂亮男人2749 days ago854

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-05-17 09:57:39

    replace into

    reply
    0
  • Cancelreply