Home  >  Article  >  PHP Framework  >  How to add yii framework in batches

How to add yii framework in batches

(*-*)浩
(*-*)浩Original
2019-12-14 09:57:322445browse

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(&#39;designlist&#39;, [&#39;name&#39;,&#39;photourl&#39;,&#39;desc&#39;], $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(
        &#39;zss_stat_series&#39;,
        [&#39;series_name&#39;,&#39;series_turnover&#39;,&#39;created_at&#39;],//字段
        $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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn