Browse Source

Update Workerman query to pass the test (#4627)

Joan Miquel 6 years ago
parent
commit
04cb0f8511
1 changed files with 8 additions and 3 deletions
  1. 8 3
      frameworks/PHP/workerman/dbraw.php

+ 8 - 3
frameworks/PHP/workerman/dbraw.php

@@ -1,11 +1,17 @@
 <?php
 function dbraw($pdo) {
+  if (! isset($_GET['queries'])) {
+    $statement = $pdo->query( 'SELECT id,randomNumber FROM World WHERE id = '. mt_rand(1, 10000) );
+    echo json_encode($statement->fetch(PDO::FETCH_ASSOC));
+
+    return;
+  }
+
   $query_count = 1;
-  if (isset($_GET['queries']) && $_GET['queries'] > 0) {
+  if ($_GET['queries'] > 1) {
     $query_count = $_GET['queries'];
   }
   if ($query_count > 500) $query_count=500;
-  $is_one = $query_count == 1;
 
   $arr = [];
   $id = mt_rand(1, 10000);
@@ -17,7 +23,6 @@ function dbraw($pdo) {
     $arr[] = ['id' => $id, 'randomNumber' => $statement->fetchColumn()];
     $id = mt_rand(1, 10000);
   }
-  if ($is_one) $arr = $arr[0];
 
   echo json_encode($arr);
 }