ChasseTresorPange/require/database.php
antux18 d0a515df65 Ajout d'un bouton suivant et précédent pour les énigmes.
Corrections traductions.
Corrections ordres des énigmes.
Corrections CSS.
Corrections DB.
2024-03-31 16:27:00 +02:00

66 lines
2.4 KiB
PHP

<?php
class Database {
public PDO $pdo_article;
public PDO $pdo_teams;
public function __construct() {
$data_path = "/../data/";
try {
// Création des bases de données
// Base des énigmes :
$this->pdo_article = new PDO("sqlite:" . dirname(__FILE__) . $data_path . "article.db");
$this->pdo_article->query('CREATE TABLE IF NOT EXISTS "puzzles" (
"id" INTEGER NOT NULL UNIQUE,
"title" TEXT NOT NULL,
"text" TEXT NOT NULL,
"hint" TEXT,
"answer" TEXT NOT NULL,
"location" TEXT NOT NULL,
"code" TEXT NOT NULL,
"reward" TEXT NOT NULL,
PRIMARY KEY("id" AUTOINCREMENT)
)');
// Base des équipes :
$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,
"pzorder" INTEGER,
PRIMARY KEY("id" AUTOINCREMENT)
)');
$this->pdo_teams->query('CREATE TABLE IF NOT EXISTS "solved" (
"puzzle_id" INTEGER NOT NULL,
"team_id" INTEGER NOT NULL
)');
$this->pdo_teams->query('CREATE TABLE IF NOT EXISTS "members" (
"name" TEXT NOT NULL,
"team_id" INTEGER NOT NULL
)');
}
catch (PDOException $exception) {
var_dump($exception);
die();
}
}
public function checkTeamExists(int $id) {
$stmt = $this->pdo_teams->prepare("SELECT * FROM teams WHERE id == :id");
$stmt->bindValue(":id", $id);
$stmt->execute();
return !empty($stmt->fetch());
}
public function getArticleNb() {
$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");
// return $query->fetch()["COUNT(*)"];
// }
}
?>