Create a new connection instance.

@param  string $driver
@param  string $database
@param  string $prefix
@param  array $config
@return Connection

@throws \InvalidArgumentException
161929
protected function createConnection( $driver, $connection, $database, $prefix = '', array $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]" );
	}
317038
protected function createConnection($connection)
    {
        // Load config connection
        $config = Arr::get($this->config, 'connections.' . $connection);
        if (is_null($config)) {
            throw new \InvalidArgumentException("config connection [$connection] not found.");
        }

        $driver = Arr::get($config, 'driver');
        if (is_null($driver)) {
            throw new \InvalidArgumentException("driver connection [$connection] not information.");
        }

        // We'll check to see if a creator method exists for the given connection. If not we
        // will check for a custom connection creator, which allows developers to create
        // connections using their own customized connection creator Closure to create it.
        if (isset($this->customCreators[$driver])) {
            return $this->callCustomCreator($driver, $config);
        } else {
            $method = 'create' . Str::studly($driver) . 'Driver';

            if (method_exists($this, $method)) {
                return $this->$method($config);
            }
        }
        throw new \InvalidArgumentException("driver [$driver] connection [$connection] not supported.");
    }
771559
public function createConnection(
		array $params,
		?Configuration $config = null,
		?EventManager $eventManager = null
	): Connection
	{
		if (!$this->initialized) {
			$this->initializeTypes();
		}

		$connection = DriverManager::getConnection($params, $config, $eventManager);

		if (!empty($this->typesMapping)) {
			$platform = $this->getDatabasePlatform($connection);
			foreach ($this->typesMapping as $dbType => $doctrineType) {
				$platform->registerDoctrineTypeMapping((string) $dbType, $doctrineType);
			}
		}
		if (!empty($this->commentedTypes)) {
			$platform = $this->getDatabasePlatform($connection);
			foreach ($this->commentedTypes as $type) {
				$platform->markDoctrineTypeCommented(Type::getType($type));
			}
		}

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

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

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

        return parent::createConnection($driver, $connection, $database, $prefix, $config);
    }
1150392
public static function createConnectionObj($driver, array $config)
    {
        switch ($driver) {
            case 'mysql' :
                return new Mysql($config);
                break;
            case 'postgresql' :
                return new Postgresql($config);
                break;
            case 'sqlite' :
                return new Sqlite($config);
                break;
            case 'oracle' :
                return new Oracle($config);
                break;
            default :
                $debug_msg = "~/config/database.php文件配置错误！不支持的数据库驱动类型 - " . strval($driver);
                throw new \InvalidArgumentException($debug_msg);
        }
    }
698713
public function createConnection($config)
    {
        $driver = $this->driver_manager->driver(array_get($config, 'driver', ''));

        if (!($driver instanceof \Doctrine\DBAL\Driver)) {
            $driver = $this->driver_manager->driver();
        }

        $params = $config;
        $params['host'] = array_get($params, 'host', array_get($config, 'server'));
        $params['user'] = array_get($params, 'user', array_get($config, 'username'));
        if (!isset($params['driverOptions'])) {
            $params['driverOptions'] = [];
        }
        if (defined('PDO::MYSQL_ATTR_MULTI_STATEMENTS')) {
            $params['driverOptions'][\PDO::MYSQL_ATTR_MULTI_STATEMENTS] = false;
        }
        $params['wrapperClass'] = array_get($config, 'wrapperClass', '\Concrete\Core\Database\Connection\Connection');
        unset($params['driver']);

        $wrapperClass = 'Doctrine\DBAL\Connection';
        if (isset($params['wrapperClass'])) {
            if (is_subclass_of($params['wrapperClass'], $wrapperClass)) {
                $wrapperClass = $params['wrapperClass'];
            } else {
                throw DBALException::invalidWrapperClass($params['wrapperClass']);
            }
        }

        $connection =  new $wrapperClass($params, $driver);
        $connection->getDatabasePlatform()->registerDoctrineTypeMapping('json', 'json_array');
        return $connection;
    }
216550
public function createConnection(?string $connection = null, array $options = []): AbstractDatabaseDriver
    {
        $config = $this->config->extract('database');

        // Check is new or legacy
        if ($config->get('connections')) {
            $connection = $connection ?: $config->get('default', 'local');
            $config     = $config->extract('connections.' . $connection);
        }

        $options = array_merge(
            [
                'driver' => $config->get('driver', 'mysql'),
                'host' => $config->get('host', 'localhost'),
                'user' => $config->get('user', 'root'),
                'password' => $config->get('password', ''),
                'database' => $config->get('name'),
                'prefix' => $config->get('prefix', 'wind_'),
            ],
            $options
        );

        $db = DatabaseFactory::getDbo($options['driver'], $options, true);

        $db->setDebug($this->config->get('system.debug', false));

        if ($db instanceof MysqlDriver && $config->get('strict', true)) {
            $this->strictMode($db);
        }

        return $db;
    }
500493
protected function configureConnection($connectionConfig)
    {
        $this->validateConnectionConfig($connectionConfig);

        $options = [];
        if (isset($connectionConfig['options'])) {
            $options = $connectionConfig['options'];
        }

        $options['driver'] = $connectionConfig['type'];

        $dialectClass = $this->dialectMap[$connectionConfig['type']];

        /** @var IDialect $dialect */
        $dialect = new $dialectClass;

        $options['platform'] = $dialect;

        $connection = DriverManager::getConnection($options);

        $dialect->initConnection($connection);

        return [
            $connection,
            $dialect
        ];
    }
1287332
public function connect($config = [], $name = false)
    {
        $this->connection = Connection::instance($config, $name);
        $query            = $this->connection->getConfig('query');

        if (__CLASS__ != trim($query, '\\')) {
            return new $query($this->connection);
        }

        $this->prefix = $this->connection->getConfig('prefix');

        return $this;
    }
441708
public function make(string $driver): ClientContract
    {
        $config = $this->app->make('config')->get("microservice-client.clients.{$driver}");
        $options = $this->serviceConfig();

        switch ($config['name']) {
            case 'restful':
                return new Restful($this->app->make('client.manager'), $config, $options);
        }

        throw new InvalidArgumentException("Unsupported driver [{$config['name']}]");
    }
263048
public function connect(array $config){

		$defaults = array(
			'resource' => null,
			'persistent' => false,
			'charset' => 'utf8'
		);

		$config += $defaults;

		if(isset($config['string']))
			$string = $config['string'];
		else{
			// String generation
			$string = '';
			foreach(array('host', 'hostaddr', 'port', 'dbname', 'user', 'password', 'connect_timeout', 'options', 'sslmode', 'service') as $cfg){
				if(isset($config[$cfg]))
					$string .= "$cfg=$config[$cfg] ";
			}
		}

		// Connect
		if(is_resource($config['resource']))
			$connection = $config['resource'];
		elseif($config['persistent'])
			$connection = @pg_pconnect($string, PGSQL_CONNECT_FORCE_NEW);
		else
			$connection = @pg_connect($string, PGSQL_CONNECT_FORCE_NEW);

		if(!is_resource($connection))
			throw new DriverException("Connection to database failed.");

		$this->resource = $connection;

		// Encoding
		@pg_set_client_encoding($this->resource, $config['charset']);

		// Schema
		if(isset($config['schema']))
			$this->runQuery('SET search_path TO "' . $config['schema'] . '"');
	}
870691
public function connect(array $params, $username = null, $password = null, array $driverOptions = array()) {
        if (!empty($this->connection)) return $this->connection;

        $metaData         = new MetaData();
        $this->connection = new Connection($params, $this, new RoutingTable($metaData->getEntityNamespaces()));
        return $this->connection;
    }
381014
public function connect(array $config){
		Connection::alias($config, 'resource', 'pdo');

		// Defaults
		$defaults = array(
			'dsn' => null,
			'resource' => null,
			'username' => null,
			'password' => null,
			'options' => array(),
		);

		$config += $defaults;

		// Connect
		if($config['resource'] instanceof PDO)
			$this->resource = $config['resource'];
		else try{
			$this->resource = new PDO($config['dsn'], $config['username'], $config['password'], $config['options']);
		} catch(PDOException $e){
			throw new DriverException($e->getMessage(), $e->getCode());
		}

		if(!$this->resource)
			throw new DriverException('Connection failed.');

		$this->driverName = $this->resource->getAttribute(PDO::ATTR_DRIVER_NAME);
	}
996827
protected function createPusherDriver(array $config): PusherBroadcaster
    {
        $connection = $config['connection'] ?? 'pusher';
        $driverConfig = config("broadcasting.connections.{$connection}");

        if (empty($driverConfig) || $driverConfig['driver'] !== 'pusher') {
            throw new RuntimeException("Could not initialize Pusher broadcast driver for connection: {$connection}.");
        }

        $appKey = Arr::get($driverConfig, 'key');
        $appSecret = Arr::get($driverConfig, 'secret');
        $appId = Arr::get($driverConfig, 'app_id');
        $options = Arr::get($driverConfig, 'options', []);

        $pusher = new Pusher($appKey, $appSecret, $appId, $options);

        return new PusherBroadcaster($pusher);
    }
1143159
public function createConnector(array $config)
    {
        if (!isset($config['driver'])) {
            throw new InvalidArgumentException('A driver must be specified.');
        }

        if ($this->container->has($key = "db.connector.{$config['driver']}")) {
            return $this->container->get($key);
        }

        switch ($config['driver']) {
            case 'mysql':
                return new MySqlConnector;
            case 'pgsql':
                return new PostgresConnector;
            case 'sqlite':
                return new SQLiteConnector;
            case 'sqlsrv':
                return new SqlServerConnector;
        }

        throw new InvalidArgumentException("Unsupported driver [{$config['driver']}]");
    }
228713
public function connect(array $config)
    {
        $options = $this->getOptions($config);

        // SQLite supports "in-memory" databases that only last as long as the owning
        // connection does. These are useful for tests or for short lifetime store
        // querying. In-memory databases may only have a single open connection.
        if ($config['database'] == ':memory:') {
            return $this->createConnection('sqlite::memory:', $config, $options);
        }

        // PDO driver will automatically create the file if permissions are granted.
        $file = $config['database'];
        if (false === strpos($file, DIRECTORY_SEPARATOR)) {
            // no directories involved, store it where we want to store it
            if (!empty($storage = config('df.db.sqlite_storage'))) {
                $file = rtrim($storage, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $file;
            }
        }
        if (false === $path = realpath($file)) {
            $storage = dirname($file);
            if (false === $path = realpath($storage)) {
                // Attempt
                @mkdir($storage);
            }
            if (false === $path = realpath($storage)) {
                logger('Failed to access storage path ' . $storage);
                throw new \InvalidArgumentException('Failed to create storage location for SQLite database.');
            }
            $path = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . basename($file);
        }

        return $this->createConnection("sqlite:{$path}", $config, $options);
    }
956955
public function createFailer($driver = null)
    {
        $driver = $driver ?: $this->config->get('queue.failer.driver', 'database');

        switch ($driver) {
            case 'database':
                $failer = new DatabaseQueueFailer(
                    $this->container->get('db'),
                    $this->config->get('queue.failer.table')
                );

                if (!$failer->isSupported()) {
                    return new NullQueueFailer();
                }

                return $failer;
                break;
            case 'pdo':
                $failer = new PdoQueueFailer(
                    $this->container->get('db')->getConnection(),
                    $this->config->get('queue.failer.table')
                );

                if ($failer->isSupported()) {
                    return new NullQueueFailer();
                }

                return $failer;
                break;
            case 'null':
            default:
                return new NullQueueFailer();
        }
    }