app.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. function db()
  3. {
  4. global $statement;
  5. $statement->execute([mt_rand(1, 10000)]);
  6. return json_encode($statement->fetch(), JSON_NUMERIC_CHECK);
  7. }
  8. function query()
  9. {
  10. global $statement;
  11. $query_count = 1;
  12. if ($_GET['q'] > 1) {
  13. $query_count = min($_GET['q'], 500);
  14. }
  15. while ($query_count--) {
  16. $statement->execute([mt_rand(1, 10000)]);
  17. $arr[] = $statement->fetch();
  18. }
  19. return json_encode($arr, JSON_NUMERIC_CHECK);
  20. }
  21. function updateraw()
  22. {
  23. global $pdo, $random, $update;
  24. $query_count = 1;
  25. if ($_GET['q'] > 1) {
  26. $query_count = min($_GET['q'], 500);
  27. }
  28. while ($query_count--) {
  29. $id = mt_rand(1, 10000);
  30. $random->execute([$id]);
  31. $world = ['id' => $id, 'randomNumber' => $random->fetchColumn()];
  32. $world['randomNumber'] = mt_rand(1, 10000);
  33. $arr[] = $world;
  34. }
  35. $pdo->beginTransaction();
  36. foreach($arr as $world) {
  37. $update->execute([$world['randomNumber'], $world['id']]);
  38. }
  39. $pdo->commit();
  40. return json_encode($arr, JSON_NUMERIC_CHECK);
  41. }
  42. function fortune()
  43. {
  44. global $fortune;
  45. //$fortune = $pdo->prepare('SELECT id,message FROM Fortune');
  46. $fortune->execute();
  47. $arr = $fortune->fetchAll(PDO::FETCH_KEY_PAIR);
  48. $arr[0] = 'Additional fortune added at request time.';
  49. asort($arr);
  50. $html = '';
  51. foreach ($arr as $id => $message) {
  52. $message = htmlspecialchars($message, ENT_QUOTES, 'UTF-8');
  53. $html .= "<tr><td>$id</td><td>$message</td></tr>";
  54. }
  55. return '<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>'
  56. .$html.
  57. '</table></body></html>';
  58. }