db-laravel-query-builder.php 877 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. // Set content type
  3. header('Content-type: application/json');
  4. require __DIR__.'/init-capsule.php';
  5. use Illuminate\Database\Capsule\Manager as Capsule;
  6. if (! isset($_GET['queries'])) {
  7. echo json_encode(
  8. Capsule::table('World')->where('id', mt_rand(1, 10000))->get()->first()
  9. );
  10. return;
  11. }
  12. // Read number of queries to run from URL parameter
  13. $query_count = 1;
  14. if ($_GET['queries'] > 1) {
  15. $query_count = $_GET['queries'] > 500 ? 500 : $_GET['queries'];
  16. }
  17. // Create an array with the response string.
  18. $arr = [];
  19. // For each query, store the result set values in the response array
  20. while (0 < $query_count--) {
  21. // Store result in array.
  22. $arr[] = Capsule::table('World')->where('id', mt_rand(1, 10000))->get()->first();
  23. }
  24. // Use the PHP standard JSON encoder.
  25. // http://www.php.net/manual/en/function.json-encode.php
  26. echo json_encode($arr);