Creates a PDO instance representing a connection to a database
@param string $dsn
@param $config
@return PDO
436454
public function createConnection($dsn, $config)
    {
        $this->username = arr_get($config, "username");
        $this->password = arr_get($config, "password");
        $this->options = arr_get($config, "options", array());

        try {
            return new PDO($dsn, $this->username, $this->password, $this->options);
        } catch (Exception $exception) {
            return $this->tryAgainLostConnection($exception, $dsn);
        }
    }
191289
protected function dsn_options($dsn)
    {
        $result = array();

        if ($this->db_pconn) {
            $result[PDO::ATTR_PERSISTENT] = true;
        }

        if (!empty($dsn['prefetch'])) {
            $result[PDO::ATTR_PREFETCH] = (int) $dsn['prefetch'];
        }

        if (!empty($dsn['timeout'])) {
            $result[PDO::ATTR_TIMEOUT] = (int) $dsn['timeout'];
        }

        return $result;
    }
69656
public function createConnection($dsn, array $config, array $options)
    {
        $username = Arr::get($config, 'username');
        $password = Arr::get($config, 'password');

        try {
            $pdo = new PDO($dsn, $username, $password, $options);
        } catch (Exception $e) {
            $pdo = $this->tryAgainIfCausedByLostConnection(
                $e, $dsn, $username, $password, $options
            );
        }

        return $pdo;
    }
855695
public static function Connect ($dsn, $options = []) {
		$dsn = is_array($dsn) ? $dsn : IniFile::GetConfig($dsn, array_keys(static::$_enableIniRuleList), $options);

		if (isset($dsn['password']) && isset($options['key'])) {
			$algorithm = isset($options['algorithm']) ? $options['algorithm'] : self::PASSWORD_HASH_ALGORITHM;
			$dsn['password'] = static::CreateSecurePassword($dsn['password'], $options['key'], $algorithm);
		}

		$dsn_options = [];
		foreach ($dsn['options'] ?? [] as $option) {
			$dsn_options[(int)$option['name']] = (int)$option['value'];
		}
		$dsn['options'] = $dsn_options;

		$dsn['schemas'] = $dsn['schemas'] ?? [];

		static::$_dsnList[static::AdjustConnectionName($options, $dsn)][static::AdjustPriority($options)][static::AdjustStackNumber($options)] = $dsn;
	}
920921
protected function dsn_connect($dsn, $mode)
    {
        $this->db_error     = false;
        $this->db_error_msg = null;

        // return existing handle
        if ($this->dbhs[$mode]) {
            $this->dbh = $this->dbhs[$mode];
            $this->db_mode = $mode;
            return $this->dbh;
        }

        // connect to database
        if ($dbh = $this->conn_create($dsn)) {
            $this->dbh          = $dbh;
            $this->dbhs[$mode]  = $dbh;
            $this->db_mode      = $mode;
            $this->db_connected = true;
        }
    }
1228512
public function connect()
    {
        return new PDO($this->getDsn(), $this->config['username'], $this->config['password'], $this->getOptions());
    }
577428
protected function getPDO()
    {
        if (null === $this->pdo) {
            $this->pdo = new \PDO($this->dsn, $this->user, $this->password, $this->options);
        }
        return $this->pdo;
    }
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;
    }
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;
    }
1172806
protected function getDsn(array $config)
    {
        // First we will create the basic DSN setup as well as the port if it is in
        // in the configuration options. This will give us the basic DSN we will
        // need to establish the PDO connections and return them back for use.
        if ($this->prefersOdbc($config)) {
            return $this->getOdbcDsn($config);
        }

        if (in_array('sqlsrv', $this->getAvailableDrivers())) {
            return $this->getSqlSrvDsn($config);
        } else {
            return $this->getDblibDsn($config);
        }
    }
618229
public static function createPdoRepository(
        $dsn, $username, $passwd = null, $options = null, $name = self::DEFAULT_NAME
    ) {
        /**
         * Create pure PDO connection.
         */
        $pdoConnection = new \PDO($dsn, $username, $passwd, $options);

        /**
         * Create PDO database repository.
         */
        $connection = new PDO($pdoConnection);

        static::$repositories[$name] = $connection;

        return $connection;
    }
287024
protected function addSslOptions($dsn, array $config)
    {
        foreach (['sslmode', 'sslcert', 'sslkey', 'sslrootcert'] as $option) {
            if (isset($config[$option])) {
                $dsn .= ";{$option}={$config[$option]}";
            }
        }

        return $dsn;
    }
636249
protected function createSocket($type, $mode, $dsn = null, $options = array())
    {
        $context = $this->getContext();
        $socket = new Socket($context, $type);

        $options = $this->options + $options;
        foreach ($options as $key => $value) {
            $socket->setSockOpt($key, $value);
        }

        $this->connect($socket, $mode, $dsn);

        return $socket;
    }
608526
public static function createFromDsn($dsn, $username, $password)
    {
        try {
            $pdo = new \PDO($dsn, $username, $password);

            return new self($pdo);
        } catch (\Exception $exception) {
            return;
        }
    }
1207556
public function connect(array $config): PDO
    {
        if (isset($config['options']) === false) {
            $config['options'] = [];
        }

        return $this->doConnect($config);
    }
1172987
public function init($config)
    {
        $this->pdo = null;

        $dns = '';
        if (is_array($config)) {
            $config += array('user' => null, 'password' => null);
            $dns = "{$config['type']}:host={$config['host']};port={$config['port']};dbname={$config['name']}";
        } else if (is_string($config)) {
            $dns = $config;
        } else if ($config instanceof PDO) {
            $this->pdo = $config;
            return $this;
        }

        try {

            // Use pipe for merging fields - sqlite compatibility
            $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET sql_mode='PIPES_AS_CONCAT'");
            $this->pdo = new PDO($dns, $config['user'], $config['password'], $options);
            $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

        } catch (Exception $ex) {
            $this->pdo = null;
            throw new RuntimeException('Cannot connect to database: ' . $ex->getMessage());
        }

        return $this;
    }
573249
public static function MakeDsn ($dsn_config) {
		$dsn = [$dsn_config['file']];
		unset($dsn_config['file']);
		foreach (static::DsnFilter($dsn_config) as $name => $config) {
			$dsn[] = sprintf('%s=%s', $name, $config);
		}
		return $dsn_config['driver'] .':'. implode(';', $dsn);
	}