From 1f6e77101fffd600dcb4d47269971707ca501504 Mon Sep 17 00:00:00 2001 From: kremsy Date: Tue, 31 Dec 2013 17:59:01 +0100 Subject: [PATCH] createdstatstables --- .../core/Statistics/StatisticManager.php | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/application/core/Statistics/StatisticManager.php b/application/core/Statistics/StatisticManager.php index d8567c67..5255c92e 100644 --- a/application/core/Statistics/StatisticManager.php +++ b/application/core/Statistics/StatisticManager.php @@ -1,4 +1,6 @@ maniaControl = $maniaControl; + $this->initTables(); + } + + /** + * Initialize necessary database tables + * + * @return bool + */ + private function initTables() { + $mysqli = $this->maniaControl->database->mysqli; + $query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_STATMETADATA. "` ( + `index` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(100) COLLATE utf8_unicode_ci NOT NULL, + `description` varchar(150) COLLATE utf8_unicode_ci NOT NULL, + PRIMARY KEY (`index`), + UNIQUE KEY `name` (`name`) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Statistics Meta Data' AUTO_INCREMENT=1;"; + + $statement = $mysqli->prepare($query); + if ($mysqli->error) { + trigger_error($mysqli->error, E_USER_ERROR); + return false; + } + $statement->execute(); + if ($statement->error) { + trigger_error($statement->error, E_USER_ERROR); + return false; + } + $statement->close(); + + $query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_STATISTICS. "` ( + `statId` int(11) NOT NULL AUTO_INCREMENT, + `playerId` int(11) NOT NULL, + `serverId` int(11) NOT NULL, + `value` int(20) COLLATE utf8_unicode_ci NOT NULL, + UNIQUE KEY `unique` (`statId`,`playerId`,`serverId`) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Statistics Meta Data' AUTO_INCREMENT=1;"; + + $statement = $mysqli->prepare($query); + if ($mysqli->error) { + trigger_error($mysqli->error, E_USER_ERROR); + return false; + } + $statement->execute(); + if ($statement->error) { + trigger_error($statement->error, E_USER_ERROR); + return false; + } + $statement->close(); + } } \ No newline at end of file