/**
  * [getDsn description].
  *
  * @return [type] [description]
  */
 public function getDsn()
 {
     if (!$this->config) {
         return '';
     }
     $dsn = array();
     $path = null;
     if ($this->config->getName()) {
         $path = $this->config->getName();
     }
     if ($this->config->getPath()) {
         $path = $this->config->getPath();
     }
     if ($this->config->getHost()) {
         if ($this->config->getPort()) {
             $dsn[] = sprintf('dbname=%s/%s:%s', $this->config->getHost(), $this->config->getPort(), $path);
         } else {
             $dsn[] = sprintf('dbname=%s:%s', $this->config->getHost(), $path);
         }
     } else {
         $dsn[] = 'dbname=' . $path;
     }
     if ($this->config->getRole()) {
         $dsn[] = 'role=' . $this->config->getRole();
     }
     if ($this->config->getChar()) {
         $dsn[] = 'charset=' . $this->config->getChar();
     }
     return $this->getPrefix() . implode(';', $dsn);
 }
Ejemplo n.º 2
0
 /**
  * [getDsn description].
  *
  * @return [type] [description]
  */
 public function getDsn()
 {
     if (!$this->config) {
         return '';
     }
     $dsn = array();
     if ($this->config->getSock()) {
         $dsn[] = 'unix_socket=' . $this->config->getSock();
     }
     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->getChar() && in_array('charset', $this->getElements())) {
         $dsn[] = 'charset=' . $this->config->getChar();
     }
     return $this->getPrefix() . implode(';', $dsn);
 }