private static function conectar()
    {
        try {
            if (self::$connect == null):
                $dsn = 'mysql:host=' . self::$host . ';dbname=' . self::$database;
                $options = [\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8'];
                self::$connect = new \PDO($dsn, self::$user, self::$pass, $options);
            endif;
        } catch (\PDOException $e) {
            self::error("<b>Erro ao se conectar ao Banco</b><br><br> #Linha: {$e->getLine()}<br> {$e->getMessage()}", $e->getCode());
            die;
        }

        self::$connect->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
        return self::$connect;
    }
private static function conectar()
    {
        try {
            if (self::$connect == null):
                $dsn = 'mysql:host=' . self::$host . ';dbname=' . self::$database;
                $options = [\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8'];
                self::$connect = new \PDO($dsn, self::$user, self::$pass, $options);
            endif;
        } catch (\PDOException $e) {
            self::error("<b>Erro ao se conectar ao Banco</b><br><br> #Linha: {$e->getLine()}<br> {$e->getMessage()}", $e->getCode());
            die;
        }

        self::$connect->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
        return self::$connect;
    }
private static function conectar ( ) { try { if ( self :: $ connect == null ) : $ dsn = 'mysql:host=' . self :: $ host . ';dbname=' . self :: $ database ; $ options = [ \ PDO :: MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8' ] ; self :: $ connect = new \ PDO ( $ dsn , self :: $ user , self :: $ pass , $ options ) ; endif ; } catch ( \ PDOException $ e ) { self :: error ( "<b>Erro ao se conectar ao Banco</b><br><br> #Linha: {$e->getLine()}<br> {$e->getMessage()}" , $ e -> getCode ( ) ) ; die ; } self :: $ connect -> setAttribute ( \ PDO :: ATTR_ERRMODE , \ PDO :: ERRMODE_EXCEPTION ) ; return self :: $ connect ; }
Conecta com o banco de dados com o pattern singleton.
Retorna um objeto PDO!
Conecta com o banco de dados com o pattern singleton . Retorna um objeto PDO!