2023-06-27 14:31:55 +02:00
|
|
|
<?php
|
|
|
|
class Database {
|
|
|
|
public PDO $pdo_article;
|
2023-06-28 20:38:52 +02:00
|
|
|
public PDO $pdo_teams;
|
2023-06-27 14:31:55 +02:00
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
$data_path = "/../data/";
|
|
|
|
try {
|
|
|
|
$this->pdo_article = new PDO("sqlite:" . dirname(__FILE__) . $data_path . "article.db");
|
2023-06-28 20:38:52 +02:00
|
|
|
$this->pdo_article->query('CREATE TABLE IF NOT EXISTS "puzzles" (
|
|
|
|
"id" INTEGER NOT NULL UNIQUE,
|
|
|
|
"text" TEXT NOT NULL,
|
|
|
|
"hint" TEXT,
|
|
|
|
"infos" TEXT NOT NULL,
|
|
|
|
"place" TEXT NOT NULL,
|
|
|
|
"code" TEXT NOT NULL,
|
|
|
|
PRIMARY KEY("id" AUTOINCREMENT)
|
|
|
|
)');
|
|
|
|
|
|
|
|
$this->pdo_teams = new PDO("sqlite:" . dirname(__FILE__) . $data_path . "teams.db");
|
|
|
|
$this->pdo_teams->query('CREATE TABLE IF NOT EXISTS "teams" (
|
|
|
|
"id" INTEGER NOT NULL UNIQUE,
|
|
|
|
PRIMARY KEY("id" AUTOINCREMENT)
|
|
|
|
)');
|
2023-06-28 21:20:16 +02:00
|
|
|
|
|
|
|
$this->pdo_teams->query('CREATE TABLE IF NOT EXISTS "solved" (
|
|
|
|
"puzzle_id" INTEGER NOT NULL,
|
|
|
|
"team_id" INTEGER NOT NULL
|
|
|
|
)');
|
2023-06-27 14:31:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
catch (PDOException $exception) {
|
|
|
|
var_dump($exception);
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getArticleNb() {
|
2023-06-28 20:38:52 +02:00
|
|
|
$query = $this->pdo_article->query("SELECT COUNT(*) FROM puzzles");
|
|
|
|
return $query->fetch()["COUNT(*)"];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTeamsNb() {
|
|
|
|
$query = $this->pdo_teams->query("SELECT COUNT(*) FROM teams");
|
2023-06-27 14:31:55 +02:00
|
|
|
return $query->fetch()["COUNT(*)"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|