fortune.php 841 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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;charset=utf8', '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>
  18. <html>
  19. <head>
  20. <title>Fortunes</title>
  21. </head>
  22. <body>
  23. <table>
  24. <tr>
  25. <th>id</th>
  26. <th>message</th>
  27. </tr>
  28. <?php
  29. foreach ( $arr as $id => &$fortune ) {
  30. ?>
  31. <tr>
  32. <td><?php echo htmlspecialchars($id, ENT_QUOTES, 'UTF-8'); ?></td>
  33. <td><?php echo htmlspecialchars($fortune, ENT_QUOTES, 'UTF-8'); ?></td>
  34. </tr>
  35. <?php } ?>
  36. </table>
  37. </body>
  38. </html>