ConnectionTemplate.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. $HOST = 'nordh.xyz';
  3. $USERNAME = 'narKampen';
  4. $PASSWORD = '9Bq.6[AcTc2ADwN-';
  5. $DATABASE = 'narKampen';
  6. $PORT = '3306';
  7. $secretKey = 'TheNarKampenSecretKey';
  8. try {
  9. $dbh = new PDO(
  10. 'mysql:host=' . $HOST . ';dbname=' . $DATABASE,
  11. $USERNAME,
  12. $PASSWORD
  13. );
  14. } catch (PDOException $e) {
  15. echo '<h1>An error har occured. </h1><pre>', $e->getMessage(), '</pre>';
  16. }
  17. // Example of setting data
  18. $realHash = md5($_GET['name'] . $_GET['score'] . $secretKey);
  19. if ($realHash == $hash) {
  20. $sth = $dbh->prepare('INSERT INTO scores VALUES (null, :name, :score)');
  21. try {
  22. $sth->execute($_GET);
  23. } catch (Exception $e) {
  24. echo '<h1>An error has ocurred.</h1><pre>', $e->getMessage(), '</pre>';
  25. }
  26. }
  27. // Example of getting data
  28. $sth = $dbh->query('SELECT * FROM scores ORDER BY score DESC LIMIT 5');
  29. $sth->setFetchMode(PDO::FETCH_ASSOC);
  30. $result = $sth->fetchAll();
  31. if (count($result) > 0) {
  32. foreach ($result as $r) {
  33. echo $r['name'], "\t", $r['score'], "\n";
  34. }
  35. }
  36. // TEMP COMMENT