dbraw.php 1006 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. //
  3. // Database Test
  4. //
  5. // Database connection
  6. // http://www.php.net/manual/en/ref.pdo-mysql.php
  7. $pdo = new PDO('mysql:host=localhost;dbname=hello_world', 'benchmarkdbuser', 'benchmarkdbpass', array(
  8. PDO::ATTR_PERSISTENT => true
  9. ));
  10. // Read number of queries to run from URL parameter
  11. $query_count = 1;
  12. if (TRUE === isset($_GET['queries'])) {
  13. $query_count = $_GET['queries'];
  14. }
  15. // Create an array with the response string.
  16. $arr = array();
  17. $id = mt_rand(1, 10000);
  18. // Define query
  19. $statement = $pdo->prepare('SELECT randomNumber FROM World WHERE id = :id');
  20. $statement->bindParam(':id', $id, PDO::PARAM_INT);
  21. // For each query, store the result set values in the response array
  22. while (0 < $query_count--) {
  23. $statement->execute();
  24. // Store result in array.
  25. $arr[] = array('id' => $id, 'randomNumber' => $statement->fetchColumn());
  26. $id = mt_rand(1, 10000);
  27. }
  28. // Use the PHP standard JSON encoder.
  29. // http://www.php.net/manual/en/function.json-encode.php
  30. echo json_encode($arr);
  31. ?>