fortune.php 779 B

123456789101112131415161718192021222324
  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=tfb-database;dbname=hello_world', 'benchmarkdbuser', 'benchmarkdbpass', array(
  8. PDO::ATTR_PERSISTENT => true
  9. ));
  10. // Define query
  11. $statement = $pdo->query( 'SELECT id, message FROM Fortune' );
  12. // Store result in array.
  13. $arr = $statement->fetchAll(PDO::FETCH_KEY_PAIR);
  14. $arr[0] = 'Additional fortune added at request time.';
  15. asort($arr);
  16. ?>
  17. <!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>
  18. <?php foreach ( $arr as $id => $fortune ) : ?>
  19. <tr><td><?php echo $id ?></td><td><?php echo htmlspecialchars($fortune, ENT_QUOTES, 'UTF-8') ?></td></tr>
  20. <?php endforeach ?></table></body></html>