yii2.0 - 查看
1 #查询 2 //方法一:查询并返回值 3 $a= WarehouseMin::find()->select('warehouse_code')->where(['id'=>4])->scalar(); 4 $a = User::findOne(['id' => \Yii::$app->user->id])->username; 5 6 //方法二:查询一个 7 $res = WarehouseMin->find()->where($where)->one(); 8 9 //方法三:查询所有 10 $model = new WarehouseMin(); 11 $data=$model->find()->where($map)->all(); 12 $data=$model->find()->where($map)->asArray()->all(); 13 14 //方法四:连表查询 15 $model = PlatformSummary::find() 16 ->joinWith(['supplierQuotes']) 17 ->where(['level_audit_status'=>[1],'is_purchase'=>1,'purchase_type'=>2]) 18 ->andWhere(['>','create_time','2018-03-06 00:00:00']) 19 ->andWhere(['product_category'=>null]) 20 ->asArray() 21 ->orderBy('id asc') 22 ->limit(500) 23 ->all(); 24 $model = ProductDescription::find()->where(['is_p'=>0])->orderBy('create_time desc')->asArray()->limit(2000)->all(); 25 26 //方法五: 27 $model = Yii::$app->db->createCommand($sql)->queryAll(); 28 29 //方法六: 30 $model= PurchaseLog::findAll(['pur_number'=>$id]); 31 if (empty($model)) 32 { 33 return '暂无日志'; 34 } 35 return $this->renderAjax('get-purchase-log',['model' =>$model]); 36 37 //方法七:输出:note 字段的值 38 $b='PO1713598256'; 39 $a = PurchaseNote::getDb() 40 ->createCommand("select group_concat(`note`) from " . PurchaseNote::tableName() . " where `pur_number` = :no") 41 ->bindParam(':no', $b) 42 ->queryScalar(); 43 44 45 46 //方法八: 47 $sku = Yii::$app->request->getQueryParam('sku'); 48 $model = ProductImgDownload::find()->andFilterWhere(['sku'=>$sku,'status'=>1])->one(); 49 if(!empty($model)){ 50 $model->status = 2; 51 $model->save(false); 52 }