If you are developing any big application or we say a Product or ERP then database operation is very very important thing. Yii is very good for CRUD operation. It use save() function for inserting data in database. But when we deal with multiple data to insert at a time then save method and loop is not a good solution. It is very time consuming which degrade performance of application.
So Yii provides createMultipleInsertCommand method. This method could be used to achieve better performance during insertion of the large amount of data into the database tables.
//only for 1.1.14 $builder=Yii::app()->db->schema->commandBuilder; $command=$builder->createMultipleInsertCommand('tbl_post', array( array('title' => 'record 1', 'text' => 'text1'), array('title' => 'record 2', 'text' => 'text2'))); $command->execute();
So for this method we have to just create data array using loop. Then just execute the command.