updateraw.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. //
  3. // Database Test
  4. //
  5. // Set content type
  6. header("Content-type: application/json");
  7. function updateraw(int $query_count) {
  8. // Database connection // TODO: use PDO instead
  9. $link = mysql_pconnect('tfb-database', 'benchmarkdbuser', 'benchmarkdbpass');
  10. mysql_select_db('hello_world', $link);
  11. // Create an array with the response string.
  12. $arr = [];
  13. // Ensure the number of queries to run from URL parameter
  14. $query_count = max(min($query_count, 500), 1);
  15. // For each query, store the result set values in the response array
  16. while ($query_count--) {
  17. $id = mt_rand(1, 10000);
  18. $randomNumber = mt_rand(1, 10000);
  19. $result = mysql_query("SELECT id, randomNumber FROM World WHERE id = $id", $link);
  20. // Store result in array.
  21. $world = ['id' => $id, 'randomNumber' => mysql_result($result, 0)];
  22. $world['randomNumber'] = $randomNumber;
  23. mysql_query("UPDATE World SET randomNumber = $randomNumber WHERE id = $id", $link);
  24. $arr[] = $world;
  25. }
  26. mysql_close($link);
  27. // Use the PHP standard JSON encoder.
  28. // http://www.php.net/manual/en/function.json-encode.php
  29. echo json_encode($arr);
  30. }
  31. updateraw((int)$_GET['queries']);