首页 > 代码库 > YII2 常用操作记录
YII2 常用操作记录
$statusdb->updateAll([‘status‘=>2], ‘earnestId=:earnestId and type=:type‘,[‘earnestId‘=>$infoArray[1],‘type‘=>4]);//改变状态
修改2个where条件的值
一次修改多个data值
$field = array();
$field[‘depId‘] = $data[‘depId‘];
$field[‘areaId‘] = $data[‘areaId‘];
$field[‘storeName‘] = $data[‘storeName‘];
$field[‘lat‘] = $data[‘lat‘];
$field[‘lng‘] = $data[‘lng‘];
$field[‘address‘] = $data[‘address‘];
$field[‘phone‘] = $data[‘phone‘];
$model->updateAll($field,‘storeId=:storeId‘,array(‘:storeId‘=>$data[‘storeId‘]));
2个二维数组数据插入(使用之前先clone否则值被覆盖)
foreach($data[‘role_parma‘] as $k=> $v1) {
if (!empty($v1)){
$_usermodel = clone $usermodel;
$_usermodel->storeId = $data[‘storeId‘];
$_usermodel->depId = $data[‘depId‘];
$_usermodel->role_parma = $v1;
$_usermodel->userId = $data[‘userId‘][$k];
$_usermodel->whoCreate = $login[‘userId‘];
$_usermodel->isDel = 0;
$_usermodel->save(false);
}
}
执行原生sql
$connection = Yii::$app->getDb();
$ziduan=explode("=", $result[‘infoAddress‘]);
$sql = "update " . $result[‘tableName‘] . " set " .$result[‘field‘]."=".$result[‘status‘]. " where " .$ziduan[0] ."=" .$ziduan[1]; //修改对方表为同意状态为2
$command = $connection->createCommand($sql);
$command->execute();
join表
public static function getBindInfo($shopId){
if(empty($shopId)) return array();
$query = self::find();
$query->asArray();
$query->where([‘mn_store_user.depId‘=>$shopId]);
$query->select("mn_store_user.role_parma,user.*");
$query->leftJoin(‘mn_user as user‘,‘mn_store_user.userId=user.mnUserId‘);
$data = $query->all();
$return = array();
if($data){
foreach($data as $val){
$return[$val[‘role_parma‘]] = $val;
}
}
return $return;
}
//打印sql
echo $query->createCommand()->getRawSql();exit;
打印错误
$db->error();
YII2 常用操作记录
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。