Home > Article > PHP Framework > How to add yii framework in batches
#Yii's ar class seems to have some problems with batch inserting data, or I haven't found a method.
Here we will first record another Yii batch insertion method, and later find the ar class batch insertion method and record it. (Recommended learning: yii framework )
$arr =[]; for ($i=0; $i < count($photolist); $i++) { $arr[$i][] = $titlelist[$i]; $arr[$i][] = $photolist[$i]; $arr[$i][] = $desclist[$i]; } Yii::$app->db->createCommand()->batchInsert('designlist', ['name','photourl','desc'], $arr)->execute();
(The current $ Arr is a two -dimensional array, so. Successfully implemented batch insertion of data in yii2
yii2一次插入多行数据 /** * @inheritdoc 批量添加 * @params $add array 添加数据 */ public function add_all($add) { $connection = \Yii::$app->db; //数据批量入库 $connection->createCommand()->batchInsert( 'zss_stat_series', ['series_name','series_turnover','created_at'],//字段 $add )->execute(); }
The above is the detailed content of How to add yii framework in batches. For more information, please follow other related articles on the PHP Chinese website!