本文整理汇总了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;
}