Browse Source

added code to /updateraw route

not sure of full test requirements for update cycle, assumed from http://www.techempower.com/benchmarks/#section=data-r6&hw=i7&test=update they want to see a db query to get ran row, then a separate db query to update same row

otherwise this could be more efficient grabbing $queries of records in one query, looping thru that dataset, then writing the update in a transaction.

or I may be totally wrong.
Steve Wasiura 12 years ago
parent
commit
4518aed2e5
1 changed files with 14 additions and 1 deletions
  1. 14 1
      php-fatfree/index.php

+ 14 - 1
php-fatfree/index.php

@@ -86,8 +86,21 @@ $f3->route(
     ),function($f3,$params) {
     /** @var Base $f3 */
     $params += array('queries' => 1); //default value
+    $db = new \DB\SQL('mysql:host=localhost;port=3306;dbname=hello_world',
+                      'benchmarkdbuser', 'benchmarkdbpass');
+    
+    $result = array();
+    $updates = array();
+        for ($i = 0; $i < $params['queries']; ++$i) {
+            $id = mt_rand(1, 10000);
+            $result[] = $db->exec('SELECT randomNumber FROM World WHERE id = ?',$id,0,false);
+            $rnu = mt_rand(1, 1000);
+            $updates[] = $db->exec('UPDATE World SET randomNumber = :ranNum WHERE id = :id',array(':ranNum'=>$rnu,':id'=>$id),0,true);
+        }
 
-    // to be continued
+        header("Content-type: application/json");
+        return $f3->serialize($updates);
+        
 });
 
 $f3->run();