Create or get existing connection.

@param  string $name
@return \PDO
@throws \Exception
169437
public function getConnection($name = null)
    {
        if ($name === null) {
            reset($this->config);
            $name = key($this->config);
        }

        if (!isset($this->config[$name])) {
            throw new \Exception('Configuration name does not exists !');
        }

        if (!isset($this->config[$name]['engine'])) {
            throw new \Exception('Engine not specified in configuration !');
        }

        $engine = $this->config[$name]['engine'];

        if (!isset($this->connections[$engine][$name])) {
            $method = 'get' . $engine;
            if (!method_exists($this, $method)) {
                throw new \Exception('Engine does not exists ! (engine: ' . $engine . ')');
            }

            $this->connections[$engine][$name] = $this->$method($name);
        }

        return $this->connections[$engine][$name];
    }
443726
public static function connection($name = 'default')
    {
        $databaseConfig = self::getConnectionConfiguration($name);

        /** @var Driver $driver */
        $driver = self::driver($name);

        $username = isset($databaseConfig['username']) ? $databaseConfig['username'] : null;
        $password = isset($databaseConfig['password']) ? $databaseConfig['password'] : null;
        $options = isset($databaseConfig['options']) ? $databaseConfig['options'] : array();

        // Create connection if we don't have it already
        if (! isset(self::$connections[$name])) {
            $connection = $driver->connect($databaseConfig, $username, $password, $options);

            self::$connections[$name] = $connection;
        }

        return self::$connections[$name];
    }
883644
public function getConnectionManager($name)
    {
        if (!isset($this->connectionManagers[$name])) {
            throw new RuntimeException(sprintf('No connection defined for database "%s". Did you forget to define a connection or is it wrong written?', $name));
        }

        return $this->connectionManagers[$name];
    }
931806
public static function createRepositoryConnection($config, $name)
    {
        /**
         * Create faker, middleware or pdo repository.
         */
        $repository = static::getRepositoryByConfig($config, $name);

        /**
         * Bind repository to context so we can reuse it later.
         */
        if ($pos = strpos($name, ':')) {
            /**
             * We're probably initializing write connection.
             */
            $originalAlias = Repository::class . '.' . substr($name, 0, $pos);
            $originalRepository = context()->get($originalAlias);
            $alias = substr($name, $pos + 1);
            $originalRepository->addAlias($alias, $repository);
            $repository->addAlias($alias == 'write' ? 'read' : 'write', $originalRepository);
        } else {
            context()->bindIfNot(Repository::class, $repository);
        }

        context()->bind(Repository::class . '.' . $name, $repository);

        return $repository;
    }
992055
protected function makeConnection($name)
    {
        $config = $this->getConnectionConfig($name);

        return $this->factory->make($config);
    }
1306218
public function createMasterClient($name)
    {
        $master = $this->getMasterAddressByName($name);
        if (!isset($master[0]) || !isset($master[1])) {
            throw new Exception('Master not found');
        }
        return new Client($master[0], $master[1], null, '', 0, $this->_authPassword);
    }
899598
public function get($name = null)
  {
    if(count($this->connectors) > 0)
    {    
      if(!is_null($name))
      {
        if(!isset($this->connectors[$name]))
          throw new \Exception("unknown Connector: $name");
        
        return $this->connectors[$name];
      }
      
      return current($this->connectors);
    }
    throw new \Exception('No Connectors found');
  }
391575
public static function connection($name = null)
    {
        if (is_null($name) || strlen($name) == 0) {
            if (is_null(static::$name)) {
                static::$name = static::$config['default'];
            }

            $name = static::$name;
        }

        if (!isset(static::$config['connection'][$name])) {
            throw new ConnectionException('The connection "' . $name . '" is not defined.');
        }

        if ($name !== static::$name) {
            static::$adapter = null;
        }

        $config = static::$config['connection'][$name];

        static::$name = $name;

        if (static::$adapter === null) {
            if ($name == 'mysql') {
                static::$adapter = new MysqlAdapter($config);
            } elseif ($name == 'sqlite') {
                static::$adapter = new SqliteAdapter($config);
            } else {
                throw new ConnectionException('This driver is not praised');
            }

            static::$adapter->setFetchMode(static::$config['fetch']);
        }

        if (static::$adapter->getConnection() instanceof PDO && $name == static::$name) {
            return static::getInstance();
        }

        return static::getInstance();
    }
383736
public static function create($name)
    {
        $name = strtolower($name);
        $classname = self::__getClassName($name);
        $path = self::__getDriverPath($name);

        if (!is_file($path)) {
            throw new Exception(
                __('Could not find Email Gateway %s.', array('<code>' . $name . '</code>'))
                . ' ' . __('If it was provided by an Extension, ensure that it is installed, and enabled.')
            );
        }

        if (!class_exists($classname)) {
            require_once $path;
        }

        return new $classname;
    }
1227812
public function setDefaultConnectionName(string $name)
    {
        if (!isset($this->connections[$name])) {
            throw new \Exception('Connection `' . $name . '` was not defined.');
        }

        $this->defaultConnectionName = $name;

        return $this;
    }
203703
public static function create(array $config, $name = 'default')
    {
        // Make sure a connection with same name doesn't exist
        if (array_key_exists($name, static::$connections)) {
            throw new Exception("Database connection {$name} already exists.");
        }

        // Set the class name, with the namespace
        $className = '\Radium\Database\\'. $config['driver'];

        // Connect to the database and return the object
        static::$connections[$name] = new $className($config, $name);
        return static::$connections[$name];
    }
1166910
public function getConnectionConfig($name)
    {
        $name = $name ?: $this->default;

        if (!is_array($config = Arr::get($this->config, $name)) && !$config) {
            throw new InvalidArgumentException("Connection [$name] not configured.");
        }

        return $config;
    }
837619
protected function makeConnection($name)
    {
        $config = $this->getConfig($name);

        // First we will check by the connection name to see if an extension has been
        // registered specifically for that connection. If it has we will call the
        // Closure and pass it the config allowing it to resolve the connection.
        if (isset($this->extensions[$name])) {
            return call_user_func($this->extensions[$name], $config, $name);
        }

        $driver = $config['driver'];

        // Next we will check to see if an extension has been registered for a driver
        // and will call the Closure if so, which allows us to have a more generic
        // resolver for the drivers themselves which applies to all connections.
        if (isset($this->extensions[$driver])) {
            return call_user_func($this->extensions[$driver], $config, $name);
        }

        return $this->factory->make($config, $name);
    }
1087889
public function connection(?string $name = null): self
    {
        $this->connection = $name ? $name : $this->app->make('config')->get('microservice-client.connection');

        return $this;
    }
110608
public function connection()
    {
        try {
            $this->_instances = new PDO($this->params['dns'], $this->params['users'], $this->params['pass'],
                    [\PDO::MYSQL_ATTR_INIT_COMMAND, 'SET NAMES utf8']);

            $attributes = array(
                    'AUTOCOMMIT', 'ERRMODE', 'CASE', 'CLIENT_VERSION', 'CONNECTION_STATUS',
                    'ORACLE_NULLS', 'PERSISTENT', 'SERVER_INFO', 'SERVER_VERSION',
                );
            foreach ($attributes as $value) {
                $this->_instances->getAttribute(constant("PDO::ATTR_$value"))."\n";
            }
        } catch (\PDOException $exc) {
            throw new \Exception('Failed to connect to database. Reason: '.$exc->getMessage());
        }

        return $this->_instances;
    }
1183810
private static function getConnectionConfiguration($name)
    {
        $databaseConfig = Configuration::get('database.connections');
        if (isset($databaseConfig[$name])) {
            $databaseConfig = $databaseConfig[$name];
        } else {
            $databaseConfig = null;
        }

        if ($databaseConfig === null) {
            throw new ConfigurationException("Database configuration for connection '" . $name . "' doesn't exists!");
        }

        if (! isset($databaseConfig['driver'])) {
            throw new ConfigurationException("Database configuration for connection '" . $name . "' is invalid!");
        }

        return $databaseConfig;
    }
773503
public function connection($name)
    {
        if ($name == 'default' && isset($this->_default))
            $name = $this->_default;

        if(!isset($this->_connections[$name]))
            throw new \Pheasant\Exception("No connection called $name registered");

        $connection = $this->_connections[$name];

        // lazily build the connection
        if(is_string($connection))
            $connection = $this->_connections[$name] =
                $this->_buildConnection(new Dsn($connection));

        return $connection;
    }