updateraw.php 1.4 KB

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