<?php

class Conexao
{
    private static $connection;

    private function __construct(){}

    public static function getConnection($D) {
		
			if($D == 1){
				// ################################################# OFFICIALL
				define('DB_HOST'        , "192.168.0.237");
				define('DB_NAME'        , "UNI");
				// ################################################# OFFICIALL
			}else{
				// ################################################# FILIAL
				define('DB_HOST'        , "192.168.0.237");
				define('DB_NAME'        , "SOF");
				// ################################################# FILIAL
			}
			define('DB_USER'        , "projetos");
			define('DB_PASSWORD'    , "projetos");
			define('DB_DRIVER'      , "sqlsrv");
		

        $pdoConfig  = DB_DRIVER . ":". "Server=" . DB_HOST . ";";
        $pdoConfig .= "Database=".DB_NAME.";";

        try {
            if(!isset($connection)){
                $connection =  new PDO($pdoConfig, DB_USER, DB_PASSWORD);
                $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            }
            return $connection;
		} catch (PDOException $e) {
			$mensagem = "Drivers disponiveis: " . implode(",", PDO::getAvailableDrivers());
			$mensagem .= "\nErro: " . $e->getMessage();
			throw new Exception($mensagem);
		}
    }
}