Ifsnop\Mysqldump\Mysqldump::parseDsn PHP Метод

parseDsn() приватный Метод

Parse DSN string and extract dbname value Several examples of a DSN string mysql:host=localhost;dbname=testdb mysql:host=localhost;port=3307;dbname=testdb mysql:unix_socket=/tmp/mysql.sock;dbname=testdb
private parseDsn ( string $dsn )
$dsn string dsn string to parse
    private function parseDsn($dsn)
    {
        if (empty($dsn) || false === ($pos = strpos($dsn, ":"))) {
            throw new Exception("Empty DSN string");
        }
        $this->dsn = $dsn;
        $this->dbType = strtolower(substr($dsn, 0, $pos));
        if (empty($this->dbType)) {
            throw new Exception("Missing database type from DSN string");
        }
        $dsn = substr($dsn, $pos + 1);
        foreach (explode(";", $dsn) as $kvp) {
            $kvpArr = explode("=", $kvp);
            $this->dsnArray[strtolower($kvpArr[0])] = $kvpArr[1];
        }
        if (empty($this->dsnArray['host']) && empty($this->dsnArray['unix_socket'])) {
            throw new Exception("Missing host from DSN string");
        }
        $this->host = !empty($this->dsnArray['host']) ? $this->dsnArray['host'] : $this->dsnArray['unix_socket'];
        if (empty($this->dsnArray['dbname'])) {
            throw new Exception("Missing database name from DSN string");
        }
        $this->dbName = $this->dsnArray['dbname'];
        return true;
    }