Insert multiple data into database in Yii 2

后端 未结 6 1239
死守一世寂寞
死守一世寂寞 2020-12-06 07:24

I have problem with my code when i\'m trying to save multiple data into database at the same time, this is my code to save into database:

foreach ($data as $         


        
6条回答
  •  猫巷女王i
    2020-12-06 08:06

    You can use Yes It Is Batch Insert to insert multiple rows. It is faster than any of the ways stated here :

    $connection->createCommand()->batchInsert('table_name', ['table_column_1', 'table_column_2'], [
        ['column_1_data_a', 'column_2_data_a'],
        ['column_1_data_b', 'column_2_data_b'],
        ['column_1_data_c', 'column_2_data_c'],
    ])->execute();
    

    Check the link for this.

提交回复
热议问题