Build the client from a dsn
Examples:

udp+influxdb://username:pass@localhost:4444/databasename

@param  string $dsn

@return Client|Database
@throws ClientException
313
public static function fromDSN($dsn)
    {
        $connParams = parse_url($dsn);
        $schemeInfo = explode('+', $connParams['scheme']);
        $modifier = null;
        $scheme = $schemeInfo[0];
        $dbName = isset($connParams['path']) ? substr($connParams['path'], 1) : null;

        if (isset($schemeInfo[1])) {
            $modifier = strtolower($schemeInfo[0]);
            $scheme = $schemeInfo[1];
        }

        if ($scheme != 'influxdb') {
            throw new ClientException($scheme . ' is not a valid scheme');
        }

        if (!in_array($modifier, ['udp'])) {
            throw new ClientException(sprintf("%s modifier specified in DSN is not supported", $modifier));
        }

        $driver = null;
        // set the UDP driver when the DSN specifies UDP
        if ($modifier == 'udp') {
            $driver = new UDP($connParams['host'], $connParams['port']);
        }

        $client = new self($driver);
        return ($dbName ? $client->selectDB($dbName) : $client);
    }
793752
public function getDsn()
    {
        if ($this->checkParam()) {
            $dsn = 'pgsql:host=' . $this->getHost() . ';';
            if (!empty($this->getPort())) {
                $dsn .= 'port=' . $this->getPort() . ';';
            }
            if (!empty($this->getDatabase())) {
                $dsn .= 'dbname=' . $this->getDatabase() . ';';
            }
            return $dsn;
        } else {
            return false;
        }
    }
438375
public static function getConnection($dsn)
    {
        if (!is_array($dsn)) {
            $dsn = self::parseDsn($dsn);
        }
        if (!isset($dsn['adapter'])) {
            throw new Exception("database adapter is missing for " . json_encode($dsn));
        }
        $class = 'Phalcon\Db\Adapter\Pdo\\' . ucfirst($dsn['adapter']);
        $conn = new $class($dsn);
        return Mixin::create($conn, new self);
    }
79635
public static function dsn(array $dsn)
    {
    	foreach (array('type','dbpath','login','password') as $key)
        {
        	if ( empty($dsn[$key]) )
        	{
        		throw new SqlError("db config invalid: {$key}");
        	}
        }

        if ( empty( $dsn['attr'] ) || !is_array( $dsn['attr'] ) )
    	{
    		$dsn['attr'] = [];
    	}

    	# force use ASSOC array
    	$dsn['attr'][PDO::ATTR_DEFAULT_FETCH_MODE] = PDO::FETCH_ASSOC;

    	if ( empty( $dsn['initcmd'] ) || !is_array( $dsn['initcmd'] ) )
    	{
    		$dsn['initcmd'] = [];
    	}
    	
    	# sql monitor
    	$dsn['monitor'] = empty( $dsn['monitor'] ) || !is_callable( $dsn['monitor'] ) ? false : $dsn['monitor'];

    	$dsn['id'] = "{$dsn['dbpath']}@{$dsn['login']}";

        return $dsn;
    }
1228575
public static function ds(array $dsn)
	{
		static $list = [];
		$dsn = SqlDataSource::dsn($dsn);
		$id = $dsn['id'];
		if ( empty( $list[$id] ) )
		{
			$list[$id] = new SqlDataSource($dsn);
		}
		return $list[$id];
	}
1242444
public static function lazyConnection($dsn, $name = false)
    {
        Eresus_Kernel::log(__METHOD__, LOG_DEBUG, '("%s", %s)', $dsn, $name);
        self::$lazyConnectionDSNs[$name] = $dsn;
    }
645600
public static function parse_dsn($dsn)
    {
        if (empty($dsn)) {
            return null;
        }

        // Find phptype and dbsyntax
        if (($pos = strpos($dsn, '://')) !== false) {
            $str = substr($dsn, 0, $pos);
            $dsn = substr($dsn, $pos + 3);
        }
        else {
            $str = $dsn;
            $dsn = null;
        }

        // Get phptype and dbsyntax
        // $str => phptype(dbsyntax)
        if (preg_match('|^(.+?)\((.*?)\)$|', $str, $arr)) {
            $parsed['phptype']  = $arr[1];
            $parsed['dbsyntax'] = !$arr[2] ? $arr[1] : $arr[2];
        }
        else {
            $parsed['phptype']  = $str;
            $parsed['dbsyntax'] = $str;
        }

        if (empty($dsn)) {
            return $parsed;
        }

        // Get (if found): username and password
        // $dsn => username:password@protocol+hostspec/database
        if (($at = strrpos($dsn,'@')) !== false) {
            $str = substr($dsn, 0, $at);
            $dsn = substr($dsn, $at + 1);
            if (($pos = strpos($str, ':')) !== false) {
                $parsed['username'] = rawurldecode(substr($str, 0, $pos));
                $parsed['password'] = rawurldecode(substr($str, $pos + 1));
            }
            else {
                $parsed['username'] = rawurldecode($str);
            }
        }

        // Find protocol and hostspec

        // $dsn => proto(proto_opts)/database
        if (preg_match('|^([^(]+)\((.*?)\)/?(.*?)$|', $dsn, $match)) {
            $proto       = $match[1];
            $proto_opts  = $match[2] ? $match[2] : false;
            $dsn         = $match[3];
        }
        // $dsn => protocol+hostspec/database (old format)
        else {
            if (strpos($dsn, '+') !== false) {
                list($proto, $dsn) = explode('+', $dsn, 2);
            }
            if (   strpos($dsn, '//') === 0
                && strpos($dsn, '/', 2) !== false
                && $parsed['phptype'] == 'oci8'
            ) {
                //oracle's "Easy Connect" syntax:
                //"username/password@[//]host[:port][/service_name]"
                //e.g. "scott/tiger@//mymachine:1521/oracle"
                $proto_opts = $dsn;
                $pos = strrpos($proto_opts, '/');
                $dsn = substr($proto_opts, $pos + 1);
                $proto_opts = substr($proto_opts, 0, $pos);
            }
            else if (strpos($dsn, '/') !== false) {
                list($proto_opts, $dsn) = explode('/', $dsn, 2);
            }
            else {
                $proto_opts = $dsn;
                $dsn = null;
            }
        }

        // process the different protocol options
        $parsed['protocol'] = $proto ?: 'tcp';
        $proto_opts = rawurldecode($proto_opts);
        if (strpos($proto_opts, ':') !== false) {
            list($proto_opts, $parsed['port']) = explode(':', $proto_opts);
        }
        if ($parsed['protocol'] == 'tcp') {
            $parsed['hostspec'] = $proto_opts;
        }
        else if ($parsed['protocol'] == 'unix') {
            $parsed['socket'] = $proto_opts;
        }

        // Get dabase if any
        // $dsn => database
        if ($dsn) {
            // /database
            if (($pos = strpos($dsn, '?')) === false) {
                $parsed['database'] = rawurldecode($dsn);
            // /database?param1=value1&param2=value2
            }
            else {
                $parsed['database'] = rawurldecode(substr($dsn, 0, $pos));
                $dsn = substr($dsn, $pos + 1);
                if (strpos($dsn, '&') !== false) {
                    $opts = explode('&', $dsn);
                }
                else { // database?param1=value1
                    $opts = array($dsn);
                }
                foreach ($opts as $opt) {
                    list($key, $value) = explode('=', $opt);
                    if (!array_key_exists($key, $parsed) || false === $parsed[$key]) {
                        // don't allow params overwrite
                        $parsed[$key] = rawurldecode($value);
                    }
                }
            }
        }

        return $parsed;
    }
827560
public function setDn($dn)
    {
        if ($dn === null) {
            $this->dn = null;
        } else {
            $this->dn = (string) $dn;
        }

        return $this;
    }
1262156
public function dsn()
    {
        // @see https://github.com/acquia/acquia-sdk-php/issues/27
        if (!isset($this['name'])) {
            throw new \OutOfBoundsException('Malformed response: expecting "name" property');
        }
        if (!isset($this['host'])) {
            throw new \OutOfBoundsException('Malformed response: expecting "host" property');
        }
        if (!isset($this['port'])) {
            throw new \OutOfBoundsException('Malformed response: expecting "port" property');
        }

        return 'mysql:dbname=' . $this['name'] . ';host=' . $this['host'] . ';port=' . $this['port'];
    }
994830
public function getDsn()
    {
        if (!$this->config) {
            return '';
        }
        $dsn = array();

        if ($this->config->getHost()) {
            $dsn[] = 'host='.$this->config->getHost();
        }

        if ($this->config->getPort()) {
            $dsn[] = 'port='.$this->config->getPort();
        }

        if ($this->config->getName()) {
            $dsn[] = 'dbname='.$this->config->getName();
        }

        if ($this->config->getUser()) {
            $dsn[] = 'user='.$this->config->getUser();
        }

        if ($this->config->getPass()) {
            $dsn[] = 'password='.$this->config->getPass();
        }

        return $this->getPrefix().implode(';', $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;
    }
435305
private function parseDsn($dsn)
    {
        $dsn = Dsn::parseFirst($dsn);

        $supportedSchemes = $this->supportedSchemes;
        if (false == in_array($dsn->getSchemeProtocol(), $supportedSchemes, true)) {
            throw new \LogicException(sprintf(
                'The given scheme protocol "%s" is not supported. It must be one of "%s".',
                $dsn->getSchemeProtocol(),
                implode('", "', $supportedSchemes)
            ));
        }

        $sslOn = false;
        $isAmqps = 'amqps' === $dsn->getSchemeProtocol();
        $isTls = in_array('tls', $dsn->getSchemeExtensions(), true);
        $isSsl = in_array('ssl', $dsn->getSchemeExtensions(), true);
        if ($isAmqps || $isTls || $isSsl) {
            $sslOn = true;
        }

        $this->schemeExtensions = $dsn->getSchemeExtensions();

        $config = array_filter(array_replace($dsn->getQuery(), [
            'host' => $dsn->getHost(),
            'port' => $dsn->getPort(),
            'user' => $dsn->getUser(),
            'pass' => $dsn->getPassword(),
            'vhost' => null !== ($path = $dsn->getPath()) ?
                (0 === strpos($path, '/') ? substr($path, 1) : $path)
                : null,
            'read_timeout' => $dsn->getFloat('read_timeout'),
            'write_timeout' => $dsn->getFloat('write_timeout'),
            'connection_timeout' => $dsn->getFloat('connection_timeout'),
            'heartbeat' => $dsn->getFloat('heartbeat'),
            'persisted' => $dsn->getBool('persisted'),
            'lazy' => $dsn->getBool('lazy'),
            'qos_global' => $dsn->getBool('qos_global'),
            'qos_prefetch_size' => $dsn->getDecimal('qos_prefetch_size'),
            'qos_prefetch_count' => $dsn->getDecimal('qos_prefetch_count'),
            'ssl_on' => $sslOn,
            'ssl_verify' => $dsn->getBool('ssl_verify'),
            'ssl_cacert' => $dsn->getString('ssl_cacert'),
            'ssl_cert' => $dsn->getString('ssl_cert'),
            'ssl_key' => $dsn->getString('ssl_key'),
            'ssl_passphrase' => $dsn->getString('ssl_passphrase'),
        ]), function ($value) { return null !== $value; });

        return array_map(function ($value) {
            return is_string($value) ? rawurldecode($value) : $value;
        }, $config);
    }
843610
public function buildDSN($option = null)
	{
		if(null === $option)
		{
			$option = $this->option;
		}
		if(isset($option['dsn']))
		{
			return $option['dsn'];
		}
		return 'sqlite' . (isset($option['version']) ? $option['version'] : '') . ':'
				 . (isset($option['path']) ? $option['path'] : ':memory:')
				 ;
	}
1062120
public function connect($dsn, $user = null, $passwd = null)
    {
        $arrayConn = array();
        $parseUrl = parse_url($dsn);
        $parseUrl = parse_url($parseUrl['path']);
        $arrayConn['host'] = $parseUrl['host'];
        $arrayConn['dbname'] = preg_replace("/[^A-z0-9_]/", '', $parseUrl['path']);
        $pdoDsn = 'mysql:host=' . $arrayConn['host'];
        $port = empty($parseUrl['port']) ? 3306 : $parseUrl['port'];
        $pdoDsn .= ';port=' . $port;
        $pdoDsn .= ';dbname=' . $arrayConn['dbname'];
        parent::connect($pdoDsn, $user, $passwd);
    }
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;
        }
    }
538507
protected function createClient($dsn, array $config, array $options)
    {
        // By default driver options is an empty array.
        $driverOptions = [];

        if (isset($config['driver_options']) && is_array($config['driver_options'])) {
            $driverOptions = $config['driver_options'];
        }

        // Check if the credentials are not already set in the options
        if (!isset($options['username']) && !empty($config['username'])) {
            $options['username'] = $config['username'];
        }
        if (!isset($options['password']) && !empty($config['password'])) {
            $options['password'] = $config['password'];
        }

        return new Client($dsn, $options, $driverOptions);
    }
1014895
protected function _dsn()
    {
        // baseline of DSN parts
        $dsn = $this->_config;

        // don't pass the username and password in the DSN
        unset($dsn['username']);
        unset($dsn['password']);
        unset($dsn['options']);
        unset($dsn['persistent']);
        unset($dsn['driver_options']);

        if (isset($dsn['port'])) {
            $seperator = ':';
            if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
                $seperator = ',';
            }
            $dsn['host'] .= $seperator . $dsn['port'];
            unset($dsn['port']);
        }

        // this driver supports multiple DSN prefixes
        // @see http://www.php.net/manual/en/ref.pdo-dblib.connection.php
        if (isset($dsn['pdoType'])) {
            switch (strtolower($dsn['pdoType'])) {
                case 'freetds':
                case 'sybase':
                    $this->_pdoType = 'sybase';
                    break;
                case 'mssql':
                    $this->_pdoType = 'mssql';
                    break;
                case 'dblib':
                default:
                    $this->_pdoType = 'dblib';
                    break;
            }
            unset($dsn['pdoType']);
        }

        // use all remaining parts in the DSN
        foreach ($dsn as $key => $val) {
            $dsn[$key] = "$key=$val";
        }

        $dsn = $this->_pdoType . ':' . implode(';', $dsn);
        return $dsn;
    }