当前位置: 首页>>代码示例>>PHP>>正文


PHP DbHelper::batchSave方法代码示例

本文整理汇总了PHP中DbHelper::batchSave方法的典型用法代码示例。如果您正苦于以下问题:PHP DbHelper::batchSave方法的具体用法?PHP DbHelper::batchSave怎么用?PHP DbHelper::batchSave使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DbHelper的用法示例。


在下文中一共展示了DbHelper::batchSave方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: batchSave

 /**
  * Save a list of models, each model may be inserted or updated depend on its existence.
  * This method could be used to achieve better performance during insertion/update of the large
  * amount of data to the database table.
  * @param \yii\db\ActiveRecord[] $models list of models to be saved.
  * If a key is not a valid column name, the corresponding value will be ignored.
  * @param array $attributeNames name list of attributes that need to be update. Defaults to empty,
  * meaning all fields of corresponding active record will be saved.
  * This parameter is ignored in the case of insertion
  * @param int $mode the save mode flag.
  * If this flag value is set to 0, any model that have a PK value is NULL will be inserted, otherwise it will be update.
  * If this flag value is set to 1, all models will be inserted regardless to PK values.
  * If this flag value is set to 2, all models will be updated regardless to PK values
  * @return \stdClass An instance of stdClass that may have one of the following fields:
  * - The 'lastId' field is the last model ID (auto-incremental primary key) inserted.
  * - The 'insertCount' is the number of rows inserted.
  * - The 'updateCount' is the number of rows updated.
  */
 public static function batchSave($models, $attributeNames = [], $mode = DbHelper::SAVE_MODE_AUTO)
 {
     $returnModels = [];
     $a = DbHelper::batchSave($models, $attributeNames, $mode, $returnModels);
     if (isset($a)) {
         $insertModels = isset($returnModels['inserted']) ? $returnModels['inserted'] : null;
         $updateModels = isset($returnModels['updated']) ? $returnModels['updated'] : null;
         static::afterBatchSave($attributeNames, $mode, $insertModels, $updateModels);
     }
     return $a;
 }
开发者ID:highestgoodlikewater,项目名称:yii2-common,代码行数:29,代码来源:ActiveRecord.php


注:本文中的DbHelper::batchSave方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。