query.php 931 B

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