Jarves\Configuration\Connection::getDsn PHP Method

getDsn() public method

public getDsn ( $withLogin = false )
    public function getDsn($withLogin = false)
    {
        $type = strtolower($this->getType());
        $dsn = $type;
        if ('sqlite' === $dsn) {
            $file = $this->getServer();
            if (substr($file, 0, 1) != '/') {
                $file = realpath($file);
            }
            $dsn .= ':' . $file;
        } else {
            $dsn .= ':host=' . $this->getServer();
            if ($this->getPort()) {
                $dsn .= ';port=' . $this->getPort();
            }
            $dsn .= ';dbname=' . $this->getName();
        }
        if ('sqlite' !== $type && $withLogin) {
            if ($this->getUsername()) {
                $dsn .= ';user=' . $this->getUsername();
            }
            if ($this->getPassword()) {
                $dsn .= ';password=' . urlencode($this->getPassword());
            }
        }
        return $dsn;
    }

Usage Example

Example #1
0
 public function getManagerConfig(Connection $connection)
 {
     $config = [];
     $config['dsn'] = $connection->getDsn();
     $config['user'] = (string) $connection->getUsername();
     $config['password'] = (string) $connection->getPassword();
     $config['options']['ATTR_PERSISTENT'] = (bool) $connection->getPersistent();
     $config['settings']['charset'] = $connection->getCharset();
     return $config;
 }