ajout du Systeme de Repo
This commit is contained in:
parent
b1b618ed1f
commit
be00b55731
|
@ -0,0 +1,3 @@
|
|||
/.idea
|
||||
/.project
|
||||
/repositories/config.json
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"host": "serveurMySql",
|
||||
"login": "leLogin",
|
||||
"password": "leMotDePasse",
|
||||
"database": "nomBaseDeDonnée"
|
||||
}
|
Loading…
Reference in New Issue