Set a database connection.
@param string $id
@param array  $config
776404
public static function create($id, array $config)
    {
        static::$databaseConnections[$id] = static::createDatabaseConnection($config);

        if (static::$activeDatabaseConnection === null) {
            static::select($id);
        }
    }
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'] . '"');
	}
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);
    }
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/>";
		}
	}
438364
public function set_connection($db)
	{
		if ( ! $db instanceof \Database_Connection)
		{
			// Get the database instance
			$db = \Database_Connection::instance($db);
		}
		$this->_connection = $db;

		return $this;
	}
1290797
public function setConfig($config)
    {
        if (is_array($config)) {
            $this->config = $config;
        } else {
            $this->config = (array) gplcart_config_get((string) $config);
            $this->setDb($this->config['database']);
            $this->config = array_merge($this->config, $this->select());
        }
    }
500195
public static function setConfig(array $config)
    {
        if ( ! isset($config['connection'])) {
            throw new DbException('can`t find `connection` parameter in database config');
        }
        $connection = &$config['connection'];
        if ( ! isset($connection['default'])) {
            throw new DbException('can`t find `default` parameter in database config');
        }
        $default = &$connection['default'];
        if ( ! is_string($default) || empty($connection[$default])) {
            throw new DbException('parameter `default` must be string and contain contains name of default connection. So given section `' .
                $default .
                '` must present in database config');
        }

        return self::$config = $config;
    }
623270
public function registerConfig(ConfigInterface $config, $id)
    {
        $this->configurationDefinitions[spl_object_hash($config)] = $config;
        $this->configurationIds[spl_object_hash($config)] = $id;
        $this->configTree->set($config->getPath(), $config);
        $config->setConfigManager($this);
    }
144584
protected function setCustomModes(PDO $connection, array $config)
    {
        $modes = implode(',', $config['modes']);

        $connection->prepare("set session sql_mode='{$modes}'")->execute();
    }
1370789
public function connect($id, array $params)
    {
        if (isset($params['connection'])) {
            $connectionParams = $params['connection'];
        } else {
            $connectionParams = $params;
            $connectionParams['driver'] = str_replace('dbal_', '', $connectionParams['driver']);
        }

        $this->persistentConnect($connectionParams);

        return new common_persistence_SqlPersistence($params, $this);
    }
1292616
public function connect( $config )
    {
        if ( $config !== NULL )
        {
            if ( NULL === $config[ 'db_name' ] || '' === $config[ 'db_name' ] )
            {
                throw new DatabaseException( 'Invalid database name.' );
            }

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

            try
            {
                $dns = "sqlite:" . $this->name;

                $this->database = new PDO( $dns );

            }
            catch ( Exception $e )
            {
                throw new DatabaseException( $e->getMessage() );
            }
        }
    }
1063524
public function addConnection(Array $config, $name = 'default')
    {
        $connectors = array(
            'mysql' => 'Mysql',
            'pgsql' => 'Postgres',
            'sqlite' => 'SQLite'
        );

        if (!isset($config['driver']) || !array_key_exists($config['driver'], $connectors)) {
            throw new \OtherCode\Database\Exceptions\ConnectionException("The selected driver is not valid.");
        }

        $connector = "OtherCode\\Database\\Connectors\\" . $connectors[$config['driver']] . 'Connector';
        $connection = new $connector();

        $this->connections[$name] = $connection->connect($config);
        return $this;
    }
811230
public function setBaseConfig(array $config)
    {
        // Check configuration.
        if (!isset($config['source'])) {
            throw new DcGeneralRuntimeException('Missing table name.');
        }

        $this->fallbackFromDatabaseToConnection($config);

        if (isset($config['connection'])) {
            if (!($config['connection'] instanceof Connection)) {
                throw new DcGeneralRuntimeException('Invalid database connection.');
            }

            $this->connection = $config['connection'];
        } else {
            // @codingStandardsIgnoreStart
            @\trigger_error(
                'You should pass a doctrine database connection to "' . __METHOD__ . '".',
                E_USER_DEPRECATED
            );
            // @codingStandardsIgnoreEnd

            $this->connection = $this->getDefaultConnection();
        }

        if (isset($config['idGenerator'])) {
            if ($config['idGenerator'] instanceof IdGeneratorInterface) {
                $idGenerator = $config['idGenerator'];
                $this->setIdGenerator($idGenerator);
            }
        }

        $this->source = $config['source'];

        if (isset($config['timeStampProperty'])) {
            $this->setTimeStampProperty($config['timeStampProperty']);
        } elseif ($this->fieldExists('tstamp')) {
            $this->setTimeStampProperty('tstamp');
        }

        if (isset($config['idProperty'])) {
            $this->setIdProperty($config['idProperty']);
        }
    }
119201
public function set_cfg(string $id = null, array $cfg = null): int
  {
    if ( null !== $cfg ){
      $cfg = $this->get_cfg(null, $cfg);
      $config = json_encode($cfg);
    }
    else{
      $config = null;
    }
    return $this->db->update($this->class_cfg['table'], [
      $this->fields['cfg'] => $config
    ], [
      $this->fields['id'] => $id
    ]);
  }
791795
public static function add_config( $config_id, $args = [] ) {
		$config                             = Config::get_instance( $config_id, $args );
		$config_args                        = $config->get_config();
		self::$config[ $config_args['id'] ] = $config_args;
	}
818250
public function setClientConfig($id, ClientConfig $configSource) {
        $sources = $this->hasOption(self::OPTION_CONFIG_SOURCES)
            ? $this->getOption(self::OPTION_CONFIG_SOURCES)
            : array()
        ;
        $sources[$id] = $configSource;
        $this->setOption(self::OPTION_CONFIG_SOURCES, $sources);
    }
599020
public function connect($config = array())
    {
        if (empty($this->mongo)) {
            $options = array();
            if (!empty($config['options'])) {
                $options = $config['options'];
            }
            $this->mongo = new \MongoClient($config['dsn'], $options);

        }
    }