當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。