dbraw.php 544 B

123456789101112131415
  1. <?php
  2. header('Content-Type: application/json');
  3. // Database connection
  4. // http://www.php.net/manual/en/ref.pdo-mysql.php
  5. $pdo = new PDO('mysql:host=tfb-database;dbname=hello_world', 'benchmarkdbuser', 'benchmarkdbpass', [
  6. PDO::ATTR_PERSISTENT => true
  7. ]);
  8. // Define query
  9. $statement = $pdo->query( 'SELECT id,randomNumber FROM World WHERE id = '. mt_rand(1, 10000) );
  10. // Use the PHP standard JSON encoder.
  11. // http://www.php.net/manual/en/function.json-encode.php
  12. echo json_encode($statement->fetch(PDO::FETCH_ASSOC), JSON_NUMERIC_CHECK);