Create a native connection
suitable for any non-laravel or non-lumen apps
any composer based frameworks
@param $config
@return Query
492132
public static function create($config)
    {

        $clientBuilder = ClientBuilder::create();

        if (!empty($config['handler'])) {
            $clientBuilder->setHandler($config['handler']);
        }

        $clientBuilder->setHosts($config["servers"]);

        $clientBuilder = self::configureLogging($clientBuilder,$config);

        $query = new Query($clientBuilder->build());

        if (array_key_exists("index", $config) and $config["index"] != "") {
            $query->index($config["index"]);
        }

        return $query;
    }
348803
public static function newInstance($config)
	{

		if (!function_exists('curl_init')) {
			throw new Exception('Curl required');
		}

		$gateway = new self();
		$gateway->setConfig($config);

		return $gateway;

	}
701141
public function createConnection(array $config)
    {
        if (! isset($config['host'])) {
            throw new InvalidArgumentException("No host provided.");
        }

        $this->setHost($config['host']);

        // We check the configuration for request headers. Some API's require
        // certain headers for all requests. Providing them in the configuration
        // makes it easier to provide these headers on each request.
        if (isset($config['headers'])) {
            $this->setHeaders($config['headers']);
        }

        return $this;
    }
421030
public function connect(array $config){

		// Defaults
		$defaults = array(
			'resource' => null,
			'charset' => 'utf8',
			'username' => ini_get('mysqli.default_user'),
			'password' => ini_get('mysqli.default_pw'),
			'database' => '',
			'socket' => ini_get('mysqli.default_socket'),
			'port' => ini_get('mysqli.default_port'),
			'host' => ini_get('mysqli.default_host'),
			'persistent' => false,
			'unbuffered' => false
		);

		$config += $defaults;

		// Connect
		if($config['resource'] instanceof mysqli)
			$this->resource = $config['resource'];
		else
			$this->resource = new mysqli($config['host'], $config['username'], $config['password'], $config['database'], $config['port'], $config['socket']);

		if($this->resource->connect_errno)
			throw new DriverException($this->resource->connect_error, $this->resource->connect_errno);

		// Set charset
		if($this->resource instanceof mysqli){
			$ok = @$this->resource->set_charset($config['charset']);
			if(!$ok)
				$this->runQuery("SET NAMES " . $config['charset']);
		}

		$this->unbuffered = $config['unbuffered'];
	}
1165496
public static function factory($config = array())
    {
        $required = array(
            'base_url',
            'username',
            'password',
        );

        $defaults = array(
            'base_url' => self::BASE_URL,
            'base_path' => self::BASE_PATH,
        );

        // Instantiate the Acquia Search plugin.
        $config = Collection::fromConfig($config, $defaults, $required);
        $client = new static($config->get('base_url'), $config);
        $client->setDefaultHeaders(array(
            'Content-Type' => 'application/json; charset=utf-8',
        ));

        // Attach the Acquia Search plugin to the client.
        $plugin = new CloudApiAuthPlugin($config->get('username'), $config->get('password'));
        $client->addSubscriber($plugin);

        return $client;
    }
848823
public function connect($config)
    {
        $this->connection = Db::connect($config);
        $this->setBuilder();
        return $this;
    }
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;
    }
1212592
public function connect(array $config, array $options)
    {
        return new PhpRedisConnection($this->createClient(array_merge(
            $config, $options, Arr::pull($config, 'options', [])
        )));
    }
536996
protected function createConnection($databaseConfig, &$error)
    {
        $error = null;
        try {
            switch ($databaseConfig['type']) {
                case 'MSSQLDatabase':
                case 'MSSQLAzureDatabase':
                    $parameters = array(
                        'UID' => $databaseConfig['username'],
                        'PWD' => $databaseConfig['password']
                    );

                    // Azure has additional parameter requirements
                    if ($this->isAzure($databaseConfig)) {
                        $parameters['database'] = $databaseConfig['database'];
                        $parameters['multipleactiveresultsets'] = 0;
                    }
                    $conn = @sqlsrv_connect($databaseConfig['server'], $parameters);
                    if ($conn) {
                        return $conn;
                    }

                    // Get error
                    if ($errors = sqlsrv_errors()) {
                        $error = '';
                        foreach ($errors as $detail) {
                            $error .= "{$detail['message']}\n";
                        }
                    } else {
                        $error = 'Unknown connection error';
                    }
                    return null;
                case 'MSSQLPDODatabase':
                    $driver = $this->getPDODriver();
                    if (!$driver) {
                        $error = 'No supported PDO driver';
                        return null;
                    }

                    // May throw a PDOException if fails
                    $conn = @new PDO($driver.':Server='.$databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password']);
                    if ($conn) {
                        return $conn;
                    } else {
                        $error = 'Unknown connection error';
                        return null;
                    }
                default:
                    $error = 'Invalid connection type: ' . $databaseConfig['type'];
                    return null;
            }
        } catch (Exception $ex) {
            $error = $ex->getMessage();
            return null;
        }
    }
380675
public function createConnector(array $config)
    {
        if (!isset($config['driver'])) {
            throw new Exception('A driver must be specified.');
        }

        switch ($config['driver']) {
            case 'mysql':
                return new MySqlConnector;
            case 'pgsql':
                return new PostgresConnector;
            case 'sqlite':
                return new SQLiteConnector;
            case 'sqlsrv':
                return new SqlServerConnector;
            case 'filesystem':
                return new FileSystemConnector;
        }
        throw new Exception("Unsupported driver [{$config['driver']}]");
    }
677767
private function makeConnection($config){
        try{
            $capsule = new Capsule;

            $capsule->addConnection($config);
            $capsule->setAsGlobal();
            $capsule->bootEloquent();

            Sentry::setupDatabaseResolver($capsule->connection()->getPdo());

        }catch(Exception $e){
            throw $e;
        }
    }
260762
public static function factory($config = array())
    {
        $defaults = array(
            'session' => '',
        );

        $required = array(
            'base_url',
            'api_user',
            'api_key',
            'session',
        );

        // Instantiate the Acquia Search plugin.
        $config = Collection::fromConfig($config, $defaults, $required);
        return new static($config->get('base_url'), $config);
    }
660668
public function connect( array $config )
	{
		$options = $this->getOptions( $config );

		$dsn = array_get( $config, 'dsn' );

		return $this->createConnection( $dsn, $config, $options );
	}
1234771
public function doConnect($config)
    {
        $connectionString = 'sqlite:' . $config['database'];
        return $this->container->build(
            '\PDO',
            array($connectionString, null, null, $config['options'])
        );
    }
428828
public static function factory($config = array())
    {
        $defaults = array();

        $required = array(
            'base_url',
            'login',
            'password'
        );

        $config = Collection::fromConfig($config, $defaults, $required);

        $client = new self($config['base_url'], $config);

        return $client;
    }
519252
public function connect(array $config)
    {
        $options = $this->getOptions($config);

        if ($config['database'] == ':memory:') {
            return $this->createConnection('sqlite::memory:', $config, $options);
        }

        $path = realpath($config['database']);

        if ($path === false) {
            throw new \InvalidArgumentException("Database does not exist.");
        }

        return $this->createConnection("sqlite:{$path}", $config, $options);
    }
1207556
public function connect(array $config): PDO
    {
        if (isset($config['options']) === false) {
            $config['options'] = [];
        }

        return $this->doConnect($config);
    }