public static function conectar() { if (empty(self::$banco_obj)) { $config = array(); $config_file = self::configFile(); if (file_exists($config_file)) { $config = parse_ini_file($config_file); $servidor = $config['banco_servidor']; $banco = $config['banco_nome']; $usuario = $config['banco_usuario']; $senha = $config['banco_senha']; $porta = $config['banco_porta']; self::$banco_config = $config; self::$banco_obj = new PDO("mysql:host={$servidor};port={$porta};dbname={$banco}", $usuario, $senha, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")); self::$banco_obj->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } else { throw new Exception('Arquivo de configuracao nao encontrado.'); } } return self::$banco_obj; }