yii的數(shù)據(jù)庫(kù)相關(guān)操作
獲取某一列數(shù)據(jù)
self::find()->where(['pid'=>$this->id])->select('id')->column();
更新操作
$model->updateAttributes(['sales_status'=>Sales::SALES_STATUS_REFUND]) === false
$updateRes = UllageGoodsModel::updateAll(['is_deleted' => 1], ['ullage_goods_id' => $diffIdArr])
public function update ($runValidation = true, $attributeNames = null) { if($runValidation && ! $this->validate($attributeNames)) { return false; } return $this->updateInternal($attributeNames); }
updateInternal不需要驗(yàn)證
$model->check_user_name = $userInfo->user_name; $model->check_user_id = $userInfo->user_id; if (!$model->update()) {}或$model->update(false, ['is_deleted']) === FALSE
updateCounters您可以使用 updateCounters()更新一個(gè)或多個(gè)計(jì)數(shù)列;參考
$post = Post::findOne(100); // UPDATE `post` SET `view_count` = `view_count` + 1 WHERE `id` = 100 $post->updateCounters(['view_count' => 1]);
Note that this method differs from updateAllCounters() in that it only saves counters for the current AR object
public static integer updateAllCounters($counters, $condition = '')

浙公網(wǎng)安備 33010602011771號(hào)