Create new connection
@param HostConfiguration $configuration Connection Configuration
@return SocketConnection
@throws ConnectionEstablishmentException
541037
public function createConnection(HostConfiguration $configuration)
    {
        if ($this->cache->offsetExists($configuration)) {
            return $this->cache->offsetGet($configuration);
        }
        $connection = new SocketConnection();
        $connection->setConfiguration($configuration);
        $connection->open();
        $this->cache->attach($configuration, $connection);
        return $connection;
    }
1257602
protected function databaseFactory(array $configuration): Database
	{
		return (new Database($this->container->get(DatabaseConnectionManager::class)->connection($configuration['configuration']), $configuration['table'], $this->classWhitelist))->setPrefix($configuration['prefix'] ?? '');
	}
889591
private function establishConnection($host, $port, Connection $connection, $timeout)
    {
        $this->logger->info(sprintf('Connecting to %s:%d...', $host, $port));

        return $this->client->connect($host, $port, $connection, $timeout);
    }
925807
public static function create($host, $user = null, $pass = null, $file, array $options = [])
    {
        $conn = new Connection(array_merge(
            [
                'host' => $host,
                'user' => $user,
                'pass' => $pass,
                'file' => $file,
                'timeout' => 10,
            ],
            $options
        ));
        $transport = new self($conn);

        return $transport;
    }
1297368
public function setConfiguration(array $configuration): ConfigurationProviderInterface
    {
        if (isset($configuration['configuration']) && $configuration['configuration']) {
            $configuration = array_merge(
                $configuration,
                $this->load($configuration['configuration']),
                array_filter($configuration)
            );
        }

        $this->configuration = $configuration;

        return $this;
    }
1366888
public function setConnection($connection)
    {
        $this->connection = $connection;
        $this->database = DB::connection($this->connection);
        return $this;
    }
238388
protected static function loadAdditionalConfiguration(Configuration $configuration)
    {
        if (null !== ($pattern = $configuration->getAdditionalConfigurationDirectory())) {
            $iterator = new \DirectoryIterator(sprintf($pattern, dirname($configuration->getIdentity())));
            foreach ($iterator as $file) {
                $configuration->merge(Configuration::createFromFile($file->getRealPath()));
            }
        }
    }
1351961
public function getConnection($thread, $configuration = [])
    {
        if (!isset($this->connections[$thread])) {
            $configuration += [
                RouterConfig::ROUTER_CONNECTION_HOST            => $this->host,
                RouterConfig::ROUTER_CONNECTION_PORT            => $this->port,
                RouterConfig::ROUTER_CONNECTION_LOGIN           => $this->user,
                RouterConfig::ROUTER_CONNECTION_PASSWORD        => $this->password,
                RouterConfig::ROUTER_CONNECTION_VHOST           => $this->vhost,
                RouterConfig::ROUTER_CONNECTION_READ_TIMEOUT    => RouterConfig::ROUTER_CONNECTION_DEFAULT_READ_TIMEOUT,
                RouterConfig::ROUTER_CONNECTION_WRITE_TIMEOUT   => RouterConfig::ROUTER_CONNECTION_DEFAULT_WRITE_TIMEOUT,
                RouterConfig::ROUTER_CONNECTION_CONNECT_TIMEOUT => RouterConfig::ROUTER_CONNECTION_DEFAULT_CONNECT_TIMEOUT,
            ];
            $connection    = new RouterConnection($this, $thread, $configuration);
            $connection->setup();
            
            $this->connections[$thread] = $connection;
        }
        
        return $this->connections[$thread];
    }
465964
protected function createConnection() {
        $config = $this->config;
        $db = new \mysqli;
        $db->connect($config['host'], $config['user'], $config['password'], $config['database'], $config['port']);
        if (!empty($config['charset'])) {
            $db->set_charset($config['charset']);
        }
        $db_sock = swoole_get_mysqli_sock($db);
        swoole_event_add($db_sock, array($this, 'onSQLReady'));
        $this->idle_pool[$db_sock] = array(
            'object' => $db,
            'socket' => $db_sock,
        );
        $this->connection_num++;
    }
944104
public function configure(array $configuration)
    {
        // allows to use the default options when a null value is passed
        if (array_key_exists('options', $configuration) && $configuration['options'] === null) {
            unset($configuration['options']);
        }

        $optionsResolver = new OptionsResolver();
        $optionsResolver
            ->setDefined(['host', 'database', 'options', 'driver_options'])
            ->setDefaults([
                'options' => ['connect' => false],
                'driver_options' => ['typeMap' => ['root' => 'array', 'document' => 'array', 'array' => 'array']],
            ])
            ->setRequired(['host', 'database'])
            ->setAllowedTypes('host', 'string')
            ->setAllowedTypes('database', 'string')
            ->setAllowedTypes('options', 'array')
            ->setAllowedTypes('driver_options', 'array')
        ;

        try {
            $this->configuration = $optionsResolver->resolve($configuration);
        } catch (\Exception $e) {
            throw new NoSQLDriverException('Wrong configuration: '.$e->getMessage(), $e->getCode(), $e);
        }
    }
773616
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $config         = $serviceLocator->get('ApplicationConfig');
        $allConnections = $libraryToConnMap = $configMap = array();

        // Early return
        if (!isset($config['datasource']['connections'])) {
            return new ConnectionManager($allConnections, $this->connectionClassMap);
        }

        foreach ($config['datasource']['connections'] as $name => $config) {
            $allConnections[$name]                = $config;
            $configMap[$config['library']][$name] = $config;
        }

        return new ConnectionManager($allConnections, $this->connectionClassMap);
    }
1027451
public static function create($host, $port)
  {
    $transceiver = new SocketTransceiver();
    $transceiver->createSocket($host, $port);
    
    return $transceiver;
  }
375138
public function addConnection(ConnectionInterface $connection)
    {
        // TODO: This should be a pool of connections


        if ($connection->isReadable()) {
            $this->readConnection = $connection;
        }

        if ($connection->isWritable()) {
            $this->writeConnection = $connection;
        }
    }
734652
protected function getNewMySqlConnection(array $config, string $connection = null)
    {
        if ($connection && isset($config[$connection])) {
            $config = array_merge($config, $config[$connection]);
        }

        return ConnectorFactory::make(FW::version())->connect($config);
    }
1303615
private function reconfigureCharacterSetCollation(Connection $connection, $characterSet, $collation)
    {
        $configuration = $this->getOptions()->getConfiguration();
        $defaultConnectionName = isset($configuration['database']['default-connection']) ? $configuration['database']['default-connection'] : '';
        if (!$defaultConnectionName) {
            // We should always have a default connection name, but don't break the process if it's not so
            return $connection;
        }
        $defaultConnectionConfiguration = isset($configuration['database']['connections'][$defaultConnectionName]) ? $configuration['database']['connections'][$defaultConnectionName] : null;
        if (!is_array($defaultConnectionConfiguration)) {
            // We should always have the configuration of the default connection name, but don't break the process if it's not so
            return $connection;
        }
        $configuration['database']['connections'][$defaultConnectionName]['character_set'] = $characterSet;
        $configuration['database']['connections'][$defaultConnectionName]['collation'] = $collation;
        $this->getOptions()->setConfiguration($configuration);
        $connection->close();

        return $this->createConnection();
    }
593807
public function createConnection(): ConnectionInterface
    {
        $driver    = $this->poolConfig->getDriver();
        $collector = ConnectionCollector::getCollector();

        if (App::isCoContext()) {
            $connectClassName = $this->getCorConnectClassName($collector, $driver);
        } else {
            $connectClassName = $this->getSyncConnectClassName($collector, $driver);
        }

        return new $connectClassName($this);
    }
304847
protected function createConnection($driver, PDO $connection, $database, $prefix = '', array $config = array())
    {
        if ($this->container->bound($key = "db.connection.{$driver}")) {
            return $this->container->make($key, array($connection, $database, $prefix, $config));
        }

        switch ($driver)
        {
            case 'mysql':
                return new MySqlConnection($connection, $database, $prefix, $config);

            case 'pgsql':
                return new PostgresConnection($connection, $database, $prefix, $config);

            case 'sqlite':
                return new SQLiteConnection($connection, $database, $prefix, $config);

            case 'sqlsrv':
                return new SqlServerConnection($connection, $database, $prefix, $config);
        }

        throw new \InvalidArgumentException("Unsupported driver [$driver]");
    }