* licensed under AGPLv3-or-later; see LICENSE.md for more information */ header('Content-Type: application/json; charset=UTF-8'); try { $pdo = new PDO("mysql:host=127.0.0.1;dbname=hitlerclicker", "root", "aA1234Aa"); } catch(PDOException $e) { echo "$e"; die('{ "status": "database offline" }'); }; /* $query = $pdo->prepare("DROP TABLE `hitlerclicker`.`stats`"); $query->execute(); $query = $pdo->prepare("DROP TABLE `hitlerclicker`.`users`"); $query->execute(); */ $query = $pdo->prepare("CREATE TABLE IF NOT EXISTS `hitlerclicker`.`stats` ( `team` VARCHAR(256) NOT NULL DEFAULT uuid() , `clicks` INT(128) unsigned NOT NULL DEFAULT '0' , `fromanon` INT(128) unsigned NOT NULL DEFAULT '0' , PRIMARY KEY (`team`) ) ENGINE = InnoDB;"); $query->execute(); $query = $pdo->prepare("CREATE TABLE IF NOT EXISTS `hitlerclicker`.`users` ( `name` VARCHAR(256) NOT NULL DEFAULT uuid() , `password` VARCHAR(256) NOT NULL , `token` VARCHAR(256) NOT NULL DEFAULT uuid() , `team` VARCHAR(256) NOT NULL DEFAULT 'axis' , `clicks` INT(128) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`name`) ) ENGINE = InnoDB;"); $query->execute(); $query = $pdo->prepare("INSERT IGNORE INTO `stats` (`team`) VALUES (:team)"); $query->execute([ "team" => "axis" ]); $query = $pdo->prepare("INSERT IGNORE INTO `stats` (`team`) VALUES (:team)"); $query->execute([ "team" => "allies" ]); $query = $pdo->prepare("INSERT IGNORE INTO `stats` (`team`) VALUES (:team)"); $query->execute([ "team" => "soviet" ]); $query = $pdo->prepare("SELECT team, clicks, fromanon FROM stats WHERE team LIKE '%' ORDER BY clicks DESC"); $query->execute(); $found = $query->fetchALL(PDO::FETCH_ASSOC); echo '{ '; $i = 0; foreach($found as $row): $i++; if ($i === sizeof($found)) { echo " \"$row[team]\": { \"clicks\": \"$row[clicks]\", \"fromanon\": \"$row[fromanon]\" }"; } else { echo " \"$row[team]\": { \"clicks\": \"$row[clicks]\", \"fromanon\": \"$row[fromanon]\" }, "; }; endforeach; echo ' }'; ?>