Browse Source

Clean php update code (#6105)

Joan Miquel 4 years ago
parent
commit
a80a413524
1 changed files with 2 additions and 2 deletions
  1. 2 2
      frameworks/PHP/php/updateraw.php

+ 2 - 2
frameworks/PHP/php/updateraw.php

@@ -4,6 +4,7 @@ header('Content-Type: application/json');
 // http://www.php.net/manual/en/ref.pdo-mysql.php
 $pdo = new PDO('mysql:host=tfb-database;dbname=hello_world', 'benchmarkdbuser', 'benchmarkdbpass',
     [PDO::ATTR_PERSISTENT => true,
+    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
     PDO::ATTR_EMULATE_PREPARES => false]
 );
 
@@ -23,8 +24,7 @@ while ($query_count--) {
     $statement->execute([$id]);
 
     // Store result in array.
-    $world = ['id' => $id, 'randomNumber' => $statement->fetchColumn()];
-    $world['randomNumber'] = mt_rand(1, 10000);
+    $world = $statement->fetch();
     $updateStatement->execute(
       [$world['randomNumber'] = mt_rand(1, 10000), $id]
     );