Insert multiple data into database in Yii 2

后端 未结 6 1237
死守一世寂寞
死守一世寂寞 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条回答
  •  青春惊慌失措
    2020-12-06 08:08

    1. You can use Yii command builder to achieve this.
    $command = Yii::app()->db->createCommand();
    
    $command->insert('table_name',array('column_1'=>$value_1),
    'column_2'=>$value_2));
    

    and so on.

    1. Write this code in loop and it will insert all records one after another.

提交回复
热议问题