58 lines
1.5 KiB
PHP
Executable File
58 lines
1.5 KiB
PHP
Executable File
<?php
|
|
|
|
class StaticRepo{
|
|
|
|
//contiens l'instance de la Connexion PDO
|
|
private static $connexion;
|
|
|
|
//utilisée dans quasi-toute les requetes, il est mieux de la stocker que de faire une requete
|
|
//a chaque fois
|
|
private static $annee;
|
|
|
|
//contiens les informations de connexion a la BDD
|
|
private static $config;
|
|
|
|
private function __construct(){
|
|
|
|
}
|
|
|
|
/**
|
|
* @return PDO instance de la connexion a la BDD
|
|
*/
|
|
public static function getConnexion(){
|
|
if(static::$config == null){
|
|
static::$config = json_decode(file_get_contents(dirname(__FILE__).DIRECTORY_SEPARATOR.'config.json'),true);
|
|
}
|
|
if(static::$connexion == null){
|
|
static::$connexion = new PDO('mysql:host='.static::$config['host'].';dbname='.static::$config['database'], static::$config['login'], static::$config['password']);
|
|
}
|
|
return static::$connexion;
|
|
}
|
|
|
|
/**
|
|
* @return String Année courante (format: AAAA-AAAA)
|
|
*/
|
|
public static function getAnnee(){
|
|
|
|
if(static::$annee == null){
|
|
$req = static::getConnexion()->prepare('SELECT Annee FROM Annees
|
|
ORDER BY Annees.Annee DESC
|
|
LIMIT 1');
|
|
$req->execute();
|
|
$result = $req->fetch(PDO::FETCH_ASSOC);
|
|
static::$annee = $result['Annee'];
|
|
}
|
|
|
|
return static::$annee;
|
|
}
|
|
|
|
/**
|
|
* @return bool test de la Connexion
|
|
*/
|
|
public static function testConnexion(){
|
|
return static::getConnexion() instanceof PDO;
|
|
}
|
|
}
|
|
|
|
?>
|