當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Query::max方法代碼示例

本文整理匯總了PHP中yii\db\Query::max方法的典型用法代碼示例。如果您正苦於以下問題:PHP Query::max方法的具體用法?PHP Query::max怎麽用?PHP Query::max使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在yii\db\Query的用法示例。


在下文中一共展示了Query::max方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: actionCreate

 /**
  * Creating new order
  * User have to give restaurant_id and it should exist in table restaurants
  * Other attributes is optional, gives status value of Order::STATUS_CREATED
  *
  * @throws \yii\db\Exception
  */
 public function actionCreate()
 {
     $role = UserRoleDetector::getUserRole();
     Yii::$app->response->format = Response::FORMAT_JSON;
     if ($role != 3 && $role != 4) {
         echo json_encode(array('error_code' => Codes::$UNAUTHORIZED, 'errors' => StatusCodeMessage::$UNAUTHORIZED), JSON_PRETTY_PRINT);
     } else {
         $params = $_REQUEST;
         //checking restaurant_id
         if (!isset($params['restaurant_id'])) {
             echo json_encode(array('status_code' => CODES::$BAD_REQUEST, 'message' => StatusCodeMessage::$BAD_REQUEST), JSON_PRETTY_PRINT);
             exit;
         } else {
             $restaurant = Restaurant::findOne(['restaurant_id' => $params['restaurant_id']]);
             if ($restaurant == null) {
                 echo json_encode(array('status_code' => CODES::$NOT_FOUND, 'message' => StatusCodeMessage::$NOT_FOUND), JSON_PRETTY_PRINT);
                 exit;
             }
         }
         $query = new Query();
         $result = $query->createCommand()->insert('orders', ["user_id" => isset($params['user_id']) ? User::findOne(['user_id' => $params['user_id']]) != null ? $params['user_id'] : null : null, "user_info" => isset($params['user_info']) ? $params['user_info'] : null, "restaurant_id" => $params['restaurant_id'], "order_info" => isset($params['order_info']) ? $params['order_info'] : '', "status" => Order::STATUS_CREATED, "other_users" => ''])->execute();
         if ($result == null) {
             echo json_encode(array('status_code' => Codes::$INERNAL, 'message' => StatusCodeMessage::$INERNAL), JSON_PRETTY_PRINT);
             exit;
         } else {
             $model = $query->from('orders')->select(['order_id', 'user_id', 'user_info', 'restaurant_id', 'order_info'])->where(['order_id' => $query->max('order_id')])->createCommand()->queryAll();
             echo json_encode(array('status_code' => Codes::$CREATED, 'message' => StatusCodeMessage::$CREATED, 'data' => $model), JSON_PRETTY_PRINT);
         }
     }
 }
開發者ID:vodas,項目名稱:praktykigda,代碼行數:37,代碼來源:OrderController.php

示例2: actionGenerateDb

 public function actionGenerateDb()
 {
     $session = Yii::$app->session;
     $flash = 'Database generated. 10 000 teachers and 100 000 students.';
     $break = false;
     $query = new Query();
     $query->select(['id'])->from('{{%teacher}}');
     $teachers_count = $query->count();
     $query = new Query();
     $query->select(['id'])->from('{{%student}}');
     $students_count = $query->count();
     for ($i = $teachers_count; $i < 10000; $i++) {
         $command = Yii::$app->db->createCommand('
           INSERT INTO {{%teacher}} (name, phone, gender)
           VALUES(\'' . self::generateString(rand(6, 10)) . '\', \'' . self::generatePhone() . '\', \'' . self::generateGender() . '\')
         ');
         $command->execute();
         if ($i - $teachers_count == 5000) {
             $break = true;
             break;
         }
         $break = true;
     }
     if (!$break) {
         for ($i = $students_count; $i < 100000; $i++) {
             $command = Yii::$app->db->createCommand('
               INSERT INTO {{%student}} (name, email, birth_dt, level)
               VALUES(\'' . self::generateString(rand(6, 10)) . '\', \'' . self::generateEmail() . '\', \'' . self::generateDate() . '\', \'' . self::generateLevel() . '\')
             ');
             $command->execute();
             if ($i - $students_count == 30000) {
                 $break = true;
                 break;
             }
         }
     }
     if (!$break) {
         $query = new Query();
         $query->select(['teacher_id'])->from('{{%teacher_student}}');
         $teacher_max = $query->max('teacher_id') + 1;
         for ($i = $teacher_max; $i <= 10000; $i++) {
             for ($j = 0; $j < rand(2, 5); $j++) {
                 $command = Yii::$app->db->createCommand('
                   INSERT INTO {{%teacher_student}} (teacher_id, student_id)
                   VALUES(\'' . $i . '\', \'' . rand(1, 100000) . '\')
                 ');
                 try {
                     $command->execute();
                 } catch (\yii\db\Exception $e) {
                     null;
                 }
             }
             if ($i - $teacher_max == 5000) {
                 $break = true;
                 break;
             }
         }
     }
     if ($break) {
         $query->select(['id'])->from('{{%teacher}}');
         $teachers = $query->count();
         $query->select(['id'])->from('{{%student}}');
         $students = $query->count();
         $flash = 'Teachers = ' . $teachers . '. Students = ' . $students . '. Please, press "Generate teachers and students" again!';
     }
     $session->setFlash('DbGenerated', $flash);
     $this->redirect('/');
 }
開發者ID:proteye,項目名稱:skyeng,代碼行數:68,代碼來源:SiteController.php


注:本文中的yii\db\Query::max方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。