creates database connect by dsn

@param string $dsn
@return DbAdapter
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);
    }
817972
private static function parseDSN($dsn)
    {
        $matches = [];

        if (!preg_match(static::DSN_REGEX, $dsn, $matches)) {
            throw new PDOException(sprintf('Invalid DSN %s', $dsn));
        }

        return array_slice($matches, 1);
    }
658789
public static function create(string $dsn, array $options = [])
    {
        $client = new \Redis();
        $parsedDsn = new RedisDsnParser($dsn);

        $connectParameters = array();
        if (null !== $parsedDsn->getSocket()) {
            $connectParameters[] = $parsedDsn->getSocket();
            $connectParameters[] = null;
        } else {
            $connectParameters[] = $parsedDsn->getHost();
            $connectParameters[] = $parsedDsn->getPort();
        }

        if (isset($options['connection_timeout'])) {
            $connectParameters[] = $options['connection_timeout'];
        } else {
            $connectParameters[] = null;
        }
        if (isset($options['connection_persistent'])) {
            $connectParameters[] = $parsedDsn->getPersistentId();
        }

        $connectMethod = !empty($options['connection_persistent']) ? 'pconnect' : 'connect';
        call_user_func_array(array($client, $connectMethod), $connectParameters);

        if (isset($options['prefix'])) {
            $client->setOption(\Redis::OPT_PREFIX, $options['prefix']);
        }

        if (null !== $parsedDsn->getPassword()) {
            $client->auth($parsedDsn->getPassword());
        }

        if (null !== $parsedDsn->getDatabase()) {
            $client->select($parsedDsn->getDatabase());
        }

        if (isset($options['serialization'])) {
            $client->setOption(\Redis::OPT_SERIALIZER, self::loadSerializationType($options['serialization']));
        }

        return $client;
    }
724580
public function createDatabase($domainName, \Transip\Model\Db $db)
    {
        return $this->getSoapClient(array_merge(array($domainName, $db), array('__method' => 'createDatabase')))->createDatabase($domainName, $db);
    }
235820
protected function dsn_options($dsn)
    {
        $result = parent::dsn_options($dsn);

        if (!empty($dsn['key'])) {
            $result[PDO::MYSQL_ATTR_SSL_KEY] = $dsn['key'];
        }

        if (!empty($dsn['cipher'])) {
            $result[PDO::MYSQL_ATTR_SSL_CIPHER] = $dsn['cipher'];
        }

        if (!empty($dsn['cert'])) {
            $result[PDO::MYSQL_ATTR_SSL_CERT] = $dsn['cert'];
        }

        if (!empty($dsn['capath'])) {
            $result[PDO::MYSQL_ATTR_SSL_CAPATH] = $dsn['capath'];
        }

        if (!empty($dsn['ca'])) {
            $result[PDO::MYSQL_ATTR_SSL_CA] = $dsn['ca'];
        }

        // Always return matching (not affected only) rows count
        $result[PDO::MYSQL_ATTR_FOUND_ROWS] = true;

        // Enable AUTOCOMMIT mode (#1488902)
        $result[PDO::ATTR_AUTOCOMMIT] = true;

        return $result;
    }
403182
public function connect(\stdClass $params): QueryBuilderInterface
	{
		list($dsn, $dbtype, $params, $options) = $this->parseParams($params);

		$dbtype = ucfirst($dbtype);
		$driver = "\\Query\\Drivers\\{$dbtype}\\Driver";

		// Create the database connection
		$db =  ! empty($params->user)
			? new $driver($dsn, $params->user, $params->pass, $options)
			: new $driver($dsn, '', '', $options);

		// Set the table prefix, if it exists
		if (isset($params->prefix))
		{
			$db->setTablePrefix($params->prefix);
		}

		// Create Query Builder object
		$conn = new QueryBuilder($db, new QueryParser($db));


		// Save it for later
		if (isset($params->alias))
		{
			$this->connections[$params->alias] = $conn;
		}
		else
		{
			$this->connections[] = $conn;
		}

		return $conn;
	}
933377
public function createConnection($dsn, array $config, array $options)
    {
        list($username, $password) = [
            Arr::get($config, 'username'), Arr::get($config, 'password'),
        ];

        try {
            return $this->createPdoConnection(
                $dsn,
                $username,
                $password,
                $options
            );
        } catch (Exception $e) {
            return $this->tryAgainIfCausedByLostConnection(
                $e,
                $dsn,
                $username,
                $password,
                $options
            );
        }
    }
105843
public function createAdminAdapter(DatabaseConnection $db) {
		$driver = $db->getInfo()->getDriver();
		switch ($driver) {
			case 'mysql':
			return new MysqlAdminAdapter($db);

			case 'pgsql':
			return new PgsqlAdminAdapter($db);

			case 'sqlite':
			return new SqliteAdminAdapter($db);

			default:
			throw new InvalidArgumentException("Unsupported driver: $driver");
		}
	}
1193569
public static function dbConnect($dsn, $user="", $passwd="", $options=array()) {

		try {
            if (!self::$objInstance){
                if (!empty($dsn)) {
                    defined('PDOLITE_DB_DSN') or define('PDOLITE_DB_DSN', $dsn);
                    defined('PDOLITE_DB_USER') or define('PDOLITE_DB_USER', $user);
                    defined('PDOLITE_DB_PASS') or define('PDOLITE_DB_PASS', $passwd);
                } 
                if (empty($options)) {
                    self::$options = array(
                        PDO::ATTR_PERSISTENT => true, 
                        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
                    );
                } else {
                        self::$options = $options;
                };
                self::$objInstance = self::getInstance(); 
            }
            return self::$objInstance;
        } catch (PDOException $e) {
            die(self::dbError($dsn));            
        }
    }
452552
public function addConnection($name, $dsn, $username = null, $password = null, $options = [])
    {
        //default driver options
        static $defaultOptions = array(
            \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
            //PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
        );
        if (isset($options['prefix'])) {
            $prefix = $options['prefix'];
            unset($options['prefix']);
        } else {
            $prefix = '';
        }
        $this->configs[$name] = [
            'dsn' => $dsn,
            'username' => $username,
            'password' => $password,
            'prefix' => $prefix,
            'options' => $options + $defaultOptions,
        ];

        return $this;
    }
713115
protected function conn_configure($dsn, $dbh)
    {
        // Initialize database structure in file is empty
        if (!empty($dsn['database']) && !filesize($dsn['database'])) {
            $data = file_get_contents(RCUBE_INSTALL_PATH . 'SQL/sqlite.initial.sql');

            if (strlen($data)) {
                $this->debug('INITIALIZE DATABASE');

                $q = $dbh->exec($data);

                if ($q === false) {
                    $error = $dbh->errorInfo();
                    $this->db_error = true;
                    $this->db_error_msg = sprintf('[%s] %s', $error[1], $error[2]);

                    rcube::raise_error(array('code' => 500, 'type' => 'db',
                        'line' => __LINE__, 'file' => __FILE__,
                        'message' => $this->db_error_msg), true, false);
                }
            }
        }
    }
146169
public function createConnection($dsn, array $config, array $options)
    {
        $username = array_get($config, 'username');

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

        return new PDO($dsn, $username, $password, $options);
    }
355027
protected function setupMongoDB($dsn, $options)
    {
        try {
            $this->client = new \MongoDB\Client($dsn, $options);
            $this->dbh    = $this->client->selectDatabase($this->dbName);
        } catch (\MongoDB\Driver\Exception $e) {
            throw new ModuleException($this, sprintf('Failed to open Mongo connection: %s', $e->getMessage()));
        }
    }
1242444
public static function lazyConnection($dsn, $name = false)
    {
        Eresus_Kernel::log(__METHOD__, LOG_DEBUG, '("%s", %s)', $dsn, $name);
        self::$lazyConnectionDSNs[$name] = $dsn;
    }
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);
    }
1072807
protected function createPdoConnection($dsn, $username, $password, $options)
    {
        return new PDO($dsn, $username, $password, $options);
    }
158186
public function db_connect($persistent = FALSE)
	{
		$this->options[PDO::ATTR_PERSISTENT] = $persistent;

		try
		{
			return new PDO($this->dsn, $this->username, $this->password, $this->options);
		}
		catch (PDOException $e)
		{
			if ($this->db_debug && empty($this->failover))
			{
				$this->display_error($e->getMessage(), '', TRUE);
			}

			return FALSE;
		}
	}