ajout du Systeme de Repo

This commit is contained in:
Lucas Mascaro 2015-12-02 11:19:29 +01:00
parent b1b618ed1f
commit be00b55731
4 changed files with 66 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/.idea
/.project
/repositories/config.json

57
repositories/StaticRepo.php Executable file
View File

@ -0,0 +1,57 @@
<?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;
}
}
?>

View File

@ -0,0 +1,6 @@
{
"host": "serveurMySql",
"login": "leLogin",
"password": "leMotDePasse",
"database": "nomBaseDeDonnée"
}

0
repositories/index.html Executable file
View File