Advertisement
Guest User

Untitled

a guest
Oct 11th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.28 KB | None | 0 0
  1. <?php
  2.     class SubmitSystem {
  3.         const DBHOST = "localhost";
  4.         const DBNAME = "csgo-stats";
  5.         const USERTABLE = "user";
  6.         const DBUSER = "csgo";
  7.         const DBPASS = "B9NH4D6JuNDUiWHtWv2E";
  8.         const COST = 12;
  9.         private static $pdo = null;
  10.  
  11.         private function getConnection(): PDO {
  12.             if (is_null(self::$pdo)) {
  13.                 self::$pdo = new PDO('mysql:host='.self::DBHOST.';dbname='.self::DBNAME, self::DBUSER, self::DBPASS);
  14.             }
  15.             return self::$pdo;
  16.         }
  17.         //Fügt einen neuen Spieler hinzu, wenn ein neuer Name auftaucht
  18.         public function addPlayer($playername){
  19.             $pdo = self::getConnection();
  20.             echo "Add new player" . $playername;
  21.             //Einfügen des Spielers in die Spielerliste
  22.             $statement = $pdo->prepare("INSERT INTO SPIELERNAMEN (SPIELERNAME) VALUES ( :SPIELERNAME)");
  23.             $statement->bindParam(':SPIELERNAME', $playername, PDO::PARAM_STR, 50);
  24.             $statement->execute();
  25.  
  26.             //Kreieren einer neuen Spieler_**Username** Tabelle
  27.             $table = "Spieler_" . $playername;
  28.             $sql = "CREATE TABLE IF NOT EXIST $table(
  29.                ID_MATCH INT(6) UNSIGNED FOREIGN KEY REFERENCES MATCHES(ID_MATCH),
  30.                ID_PLAYER INT(6) UNSIGNED,
  31.                STATS VARCHAR(60) NOT NULL
  32.                )";
  33.             echo $sql;
  34.             $pdo->exec($sql);
  35.             $pdo = NULL;
  36.         }
  37.         //Sieht nach ob der Spieler schon existiert anhand des Spielernamens
  38.         public function checkIfPlayerExists($playername){
  39.             $pdo = self::getConnection();
  40.             $statement = $pdo->prepare("SELECT ID_PLAYER FROM SPIELERNAMEN WHERE SPIELERNAME = :playername");
  41.             $statement->bindParam(':playername', $playername, PDO::PARAM_STR, 50);
  42.             $statement->execute();
  43.             $pdo = NULL;
  44.             if ($statement->rowcount() < 1)
  45.                 return false;
  46.             else
  47.                 return true;
  48.         }
  49.         //Checkt ob das Spiel schon im System ist
  50.         //Kann zur Not noch mit Details erweitert werden!
  51.         public function checkIfGameAlreadyExists($datum, $map, $twin, $tloss, $ctwin, $ctloss){
  52.             $result = $twin . ", " . $tloss . ", " . $ctwin . ", " . $ctloss;
  53.             $pdo = self::getConnection();
  54.             $statement = $pdo->prepare("SELECT ID_MATCH FROM MATCHES WHERE DATUM = :datum AND MAP = :map AND RESULT = :result");
  55.             $statement->bindParam(':datum', $datum, PDO::PARAM_STR, 50);
  56.             $statement->bindParam(':map', $map, PDO::PARAM_STR, 20);
  57.             $statement->bindParam(':result', $result, PDO::PARAM_STR, 50);
  58.             $statement->execute();
  59.             $pdo = NULL;
  60.             if ($statement->rowcount() < 1){
  61.                 return false;
  62.             } else {
  63.                 return true;
  64.             }
  65.         }
  66.  
  67.         public function getUserIDFromName($playername){
  68.             $pdo = self::getConnection();
  69.             $statement = $pdo->prepare("SELECT ID_PLAYER FROM SPIELERNAMEN WHERE SPIELERNAME = : playername");
  70.             $statement->bindParam(':playername', $playername, PDO::PARAM_STR, 50);
  71.             $statement->execute();
  72.             $playerid = $statement->fetch();
  73.             $pdo = NULL;
  74.             return $playerid;
  75.         }
  76.  
  77.         public function insertMatchIntoMatchTable($statsF, $statsE, $res, $datum, $map){
  78.             $pdo = self::getConnection();
  79.             $statement = $pdo->prepare("INSERT INTO MATCHES (RESULT, TEAM1, TEAM2, DATUM, MAP) VALUES (:res, :t1, :t2, :datum, :map)");
  80.             $statement->bindParam(':res', $res, PDO::PARAM_STR, 50);
  81.             $statement->bindParam(':t1', $statsF, PDO::PARAM_STR, 60);
  82.             $statement->bindParam(':t2', $statsE, PDO::PARAM_STR, 60);
  83.             $statement->bindParam(':datum', $datum, PDO::PARAM_STR, 50);
  84.             $statement->bindParam(':map', $map, PDO::PARAM_STR, 20);
  85.             $statement->execute();
  86.            
  87.  
  88.             //Query um die Match ID zurückzugeben
  89.             $stmt = $pdo->prepare("SELECT ID_MATCH FROM MATCHES WHERE RESULT = :res AND DATUM = :datum AND MAP = :map");
  90.             $stmt->bindParam(':datum', $datum, PDO::PARAM_STR, 50);
  91.             $stmt->bindParam(':map', $map, PDO::PARAM_STR, 20);
  92.             $stmt->bindParam(':res', $res, PDO::PARAM_STR, 50);
  93.             $stmt->execute();
  94.             $matchid = $stmt->fetch();
  95.             $pdo = NULL;
  96.             return $matchid;
  97.         }
  98.  
  99.         public function insertMatchIntoUserTable($user, $uid, $matchid, $statsUser, $datum, $map){
  100.             $pdo = self::getConnection();
  101.             $table = "Spieler_" . $user;
  102.             $statement = $pdo->prepare("INSERT INTO $table(ID_MATCH, DATUM, ID_PLAYER, STATS, MAP) VALUES (:idm, :datum, :idp, :stats, :map");
  103.             $statement->bindParam(':idm', $matchid, PDO::PARAM_INT, 6);
  104.             $statement->bindParam(':idp', $uid, PDO::PARAM_INT, 6);
  105.             $statement->bindParam(':datum', $datum, PDO::PARAM_STR, 50);
  106.             $statement->bindParam(':stats', $statsUser, PDO::PARAM_STR, 60);
  107.             $statement->bindParam(':map', $map, PDO::PARAM_STR, 20);
  108.             $statement->execute();
  109.             $pdo = NULL;
  110.         }
  111.     }
  112.  
  113.  
  114. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement