yii的数据库相关操作

获取某一列数据

 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不需要验证

 $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()更新一个或多个计数列;参考

$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 = '')

上一篇:MYSQL数据库相关操作---读书笔记分享


下一篇:mysq数据库相关操作