dborm.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. //
  3. // Database Test
  4. //
  5. // Set content type
  6. header("Content-type: application/json");
  7. // Database connection
  8. // http://www.php.net/manual/en/ref.pdo-mysql.php
  9. // $pdo = new PDO('mysql:host=localhost;dbname=hello_world', 'benchmarkdbuser', 'benchmarkdbpass');
  10. # inclue the ActiveRecord library
  11. require_once 'php-activerecord/ActiveRecord.php';
  12. ActiveRecord\Config::initialize(function($cfg)
  13. {
  14. $cfg->set_model_directory('models');
  15. $cfg->set_connections(array('development' =>
  16. 'mysql://benchmarkdbuser:benchmarkdbpass@localhost/hello_world'));
  17. });
  18. // Read number of queries to run from URL parameter
  19. $query_count = 1;
  20. if (!empty($_GET)) {
  21. $query_count = $_GET["queries"];
  22. }
  23. // Create an array with the response string.
  24. $arr = array();
  25. // For each query, store the result set values in the response array
  26. for ($i = 0; $i < $query_count; $i++) {
  27. // Choose a random row
  28. // http://www.php.net/mt_rand
  29. $id = mt_rand(1, 10000);
  30. $world = World::find_by_id($id);
  31. // Store result in array.
  32. $arr[] = $world->to_json();
  33. }
  34. // Use the PHP standard JSON encoder.
  35. // http://www.php.net/manual/en/function.json-encode.php
  36. echo json_encode($arr);
  37. ?>