projet-php/repositories/StaticRepo.php

37 lines
944 B
PHP
Executable File

<?php
class StaticRepo{
//contiens l'instance de la Connexion PDO
private static $connexion;
//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 bool test de la Connexion
*/
public static function testConnexion(){
return static::getConnexion() instanceof PDO;
}
}
?>