Browse Source

Php-ngx bulk update (#5198)

* Php-ngx bulk update

* php-ngx async bulk update

* Small change to rerun travis
Joan Miquel 5 years ago
parent
commit
f97f5894cd
2 changed files with 10 additions and 9 deletions
  1. 5 3
      frameworks/PHP/php-ngx/app-async.php
  2. 5 6
      frameworks/PHP/php-ngx/app.php

+ 5 - 3
frameworks/PHP/php-ngx/app-async.php

@@ -75,14 +75,16 @@ function update()
         $query_count = min($params, 500);
     }
 
+    $update = '';
     while ($query_count--) {
-        $id                    = mt_rand(1, 10000);
-        $world                 = (yield from $my->query("SELECT id,randomNumber FROM World WHERE id = $id"))[0];
+        $id     = mt_rand(1, 10000);
+        $world  = (yield from $my->query("SELECT id,randomNumber FROM World WHERE id = $id"))[0];
         
         $world['randomNumber'] = mt_rand(1, 10000);
-        yield from $my->query("UPDATE World SET randomNumber = {$world['randomNumber']} WHERE id = $id");
+        $update .="UPDATE World SET randomNumber = {$world['randomNumber']} WHERE id = $id;";
         $arr[] = $world;
     }
+    yield from $my->query($update);
     unset($my);
     echo json_encode($arr);
 }

+ 5 - 6
frameworks/PHP/php-ngx/app.php

@@ -46,21 +46,20 @@ function update()
         $query_count = min($params, 500);
     }
 
-    $statement       = $pdo->prepare('SELECT randomNumber FROM World WHERE id=?');
-    $updateStatement = $pdo->prepare('UPDATE World SET randomNumber=? WHERE id=?');
+    $statement = $pdo->prepare('SELECT randomNumber FROM World WHERE id=?');
+    $update    = '';
 
     while ($query_count--) {
         $id = mt_rand(1, 10000);
         $statement->execute([$id]);
 
         $world = ['id' => $id, 'randomNumber' => $statement->fetchColumn()];
-        $updateStatement->execute(
-            [$world['randomNumber'] = mt_rand(1, 10000), $id]
-        );
+        $world['randomNumber'] = mt_rand(1, 10000);
+        $update .= "UPDATE World SET randomNumber={$world['randomNumber']} WHERE id=$id;";
 
         $arr[] = $world;
     }
-
+    $pdo->exec($update);
     echo json_encode($arr, JSON_NUMERIC_CHECK);
 }