Establish a database connection.

@param  array  $config
@return \PDO

@throws \InvalidArgumentException
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);
    }
10296
public function setDbConn($dbconfig = [])
    {
        if (empty($dbconfig)) {
            $this->dbconfig = config('database');
            //$this->dbconfig = Config::get('database');
        } else {
            $this->dbconfig = $dbconfig;
        }
        return $this;
    }
1013797
public function authenticate(array $config)
    {
        if (!$this->client) {
            throw new InvalidArgumentException('The client instance was not given to the password authenticator.');
        }

        if (!array_key_exists('username', $config) || !array_key_exists('password', $config)) {
            throw new InvalidArgumentException('The password authenticator requires a username and password.');
        }

        $this->client->authenticate(Client::AUTH_HTTP_PASSWORD, $config['username'], $config['password']);

        return $this->client;
    }
546741
public function connect(array $config)
	{
		$sqsConfig = array_only($config, array('key', 'secret', 'region', 'default_cache_config'));

		$sqs = SqsClient::factory($sqsConfig);

		return new SqsQueue($sqs, $config['queue']);
	}
226878
private function connect($config) {
		try {
			$this->pdoObject = new \PDO(
					$config["type"].':host=' . $config["serverName"] . ';dbname='
					. $config["dbName"] . ';port=' . $config["port"],
					$config["user"], $config["password"]);
			$this->pdoObject->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
			$this->pdoObject->exec("SET CHARACTER SET utf8");

		} catch (\PDOException $e) {
			print "Error!: " . $e->getMessage() . "<br/>";
		}
	}
438867
public function connect(Array $config)
    {
        $dsn = $this->getDSN($config);
        $options = $this->getOptions($config);

        $connection = $this->createConnection($dsn, $config, $options);

        if (isset($config['charset'])) {
            $connection->prepare("set names '" . $config['charset'] . "'")->execute();
        }

        if (isset($config['timezone'])) {
            $connection->prepare("set time zone '" . $config['timezone'] . "'")->execute();
        }

        return $connection;
    }
977835
protected function createDatabaseDriver(array $config)
    {
        $connection = $this->app['db']->connection(Arr::get($config, 'connection'));

        return $this->repository(
            new DatabaseStore(
                $connection, $config['table'], $this->getPrefix($config)
            )
        );
    }
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;
    }
872965
public function connect(array $config)
    {
        // First we'll create the basic DSN and connection instance connecting to the
        // using the configuration option specified by the developer. We will also
        // set the default character set on the connections to UTF-8 by default.
        $connection = $this->createConnection(
            $this->getDsn($config), $config, $this->getOptions($config)
        );

        $this->configureEncoding($connection, $config);

        // Next, we will check to see if a timezone has been specified in this config
        // and if it has we will issue a statement to modify the timezone with the
        // database. Setting this DB timezone is an optional configuration item.
        $this->configureTimezone($connection, $config);

        $this->configureSchema($connection, $config);

        // Postgres allows an application_name to be set by the user and this name is
        // used to when monitoring the application with pg_stat_activity. So we'll
        // determine if the option has been specified and run a statement if so.
        $this->configureApplicationName($connection, $config);

        return $connection;
    }
682602
public function connect(array $config)
    {
        return new RedisQueue(
            $this->redis, $config['queue'],
            $config['connection'] ?? $this->connection,
            $config['retry_after'] ?? 60,
            $config['block_for'] ?? null
        );
    }
115115
public function initialize(array $config)
    {
        $this->table('users');
        $this->displayField('email');
        $this->primaryKey('id');
        $this->addBehavior('Timestamp');

        $this->belongsTo('Users.Roles');

        $this->postType = [
            'formFields' => [
                'id',
                'email',
                'new_password' => [
                    'type' => 'password',
                ],
                'confirm_password' => [
                    'type' => 'password'
                ],
                'role_id',
                'active' => [
                    'type' => 'checkbox'
                ],
            ],
            'tableColumns' => [
                'id' => [],
                'email' => [],
                'role_id' => [
                    'get' => 'role.name'
                ],
                'active',
                'created' => []
            ],
            'filters' => [
                'email'
            ],
            'query' => function ($query) {

                $query->contain(['Roles']);

                return $query;
            },
        ];
    }
214501
public function buildPDO(array $config=null) {
		if(!$config)
			$config = $this->config;
		$driver = $config['driver'];
		$user = isset($config['user']) ? $config['user']:'root';
		$password = isset($config['password']) ? $config['password']:'';
		$database = isset($config['database']) ? $config['database']:null;

		switch($driver) {
			case 'pgsql':
				$parameters = 'pgsql:host='.$config['host'].(isset($config['port']) ? ' port='.$config['port']:'').($database ? ' dbname='.$database:'');
				$this->pdo = new \PDO($parameters, $user, $password);
				break;
			case 'mssql':
				$parameters = 'mssql:host='.$config['host'].($database ? ';dbname='.$database:'');
				$this->pdo = new \PDO($parameters, $user, $password);
				break;
			case 'sqlite':
				$pdo = $this->pdo = new \PDO('sqlite:'.$database);
	
				require_once __DIR__.'/sqlite_functions.php';

				break;
			default:
				$parameters = 'mysql:host='.$config['host'].(isset($config['port']) ? ';port='.$config['port']:'').($database ? ';dbname='.$database:'');
				$this->pdo = new \PDO($parameters, $user, $password, [\PDO::MYSQL_ATTR_FOUND_ROWS => true, \PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8']);
		}
		$this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
	}
943469
public function setConfig($config)
    {
        if (is_array($config)) {
            $this->config = $this->createConfig($config);
        } elseif ($config instanceof ConfigInterface) {
            $this->config = $config;
        } else {
            throw new InvalidArgumentException(
                'Configuration must be an array or a ConfigInterface object.'
            );
        }
        return $this;
    }
784003
public function createConnector(array $config)
    {
        if (! isset($config['driver'])) {
            throw new \InvalidArgumentException("A driver must be specified.");
        }

        if ($this->container->bound($key = "db.connector.{$config['driver']}")) {
            return $this->container->make($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']}]");
    }
1291547
public function connect(array $config)
    {
        $options = $this->getOptions($config);

        return $this->createConnection($this->getDsn($config), $config, $options);
    }
1273374
public function build(array $config)
    {
        $default = [
            'class' => null,
            'type' => null,
            'arguments' => [],
            '_key' => null,
        ];
        $config = array_merge($default, $config);
        $componentBuilder = $this->components[$config['_key']] ?? null;
        if ($componentBuilder === null) {
            throw new \InvalidArgumentException(sprintf('Invalid "_key:%s" in configuration.', $config['_key']));
        }
        return $componentBuilder->make($config['class'], $config['type'], $config['arguments']);
    }
899352
public static function createRedisByConfig(array $config) {
        $Redis = new Connection();
        $Redis->setHost(@$config['host'])
            ->setPort(@$config['port']);
        (isset($config['persistent']))      && $Redis->setPersistent($config['persistent']);
        (isset($config['connect_timeout'])) && $Redis->setConnectTimeout($config['connect_timeout']);
        (isset($config['connect_tries']))   && $Redis->setConnectTries($config['connect_tries']);
        return $Redis;
    }