<?php if(!isset($_SESSION)){session_start();}

include_once(__DIR__.'/../../../_defines/global.php');
include_once(__DIR__.'/../../../_defines/fncr.php');

if(DEVELOPER){
  ini_set('display_errors',1);
  ini_set('display_startup_erros',1);
}

// Partes do Domínio
$dominio_partes = explode('.', $_SERVER['SERVER_NAME']);

// TIMEZONE (FUSO HORÁRIOS)
date_default_timezone_set("America/Sao_paulo");

if(DEVELOPER || $dominio_partes[0]=="fncr"){

  // CONECTANDO AO FNCR
  class Coneccao{
    private $bd;
    public function __construct(){
      try {
        $this->bd = new PDO('mysql:host='.GLOBAL_SERVER.';dbname='.GLOBAL_FNCR_BD, GLOBAL_FNCR_USER, GLOBAL_FNCR_PASS);
        $this->bd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $this->bd->exec("SET NAMES utf8");
        $this->bd->exec("SET time_zone='-03:00'");
      }catch(PDOException $e){throw new PDOException($e->getMessage());}
    }
    public function getConexao(){ return $this->bd; }
    public function lastId(){
      $stmt = $this->bd->query("SELECT LAST_INSERT_ID()");
      return $stmt->fetchColumn();
    }
  }
  $bd = new Coneccao();

  // CONEXÃO PARA OS CLUBES
  class ConeccaoClube{
    private $bd;
    public function __construct($bd,$us=null,$sn=null,$hs=null){
      try {
        $this->bd = new PDO('mysql:host='.GLOBAL_SERVER.';dbname='.$bd, GLOBAL_CLUBE_USER, GLOBAL_CLUBE_PASS);
        $this->bd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
      }catch(PDOException $e){
        $this->bd = false;
        return $this->bd;
        throw new PDOException($e->getMessage());
      }
    }
    public function getConexao(){return $this->bd;}
  }

}else{ exit; }
?>