Zend_Db_Adapter_Pdo_Abstract::_dsn PHP Method

_dsn() protected method

Creates a PDO DSN for the adapter from $this->_config settings.
protected _dsn ( ) : string
return string
    protected function _dsn()
    {
        // baseline of DSN parts
        $dsn = $this->_config;
        // don't pass the username, password, charset, persistent and driver_options in the DSN
        unset($dsn['username']);
        unset($dsn['password']);
        unset($dsn['options']);
        unset($dsn['charset']);
        unset($dsn['persistent']);
        unset($dsn['driver_options']);
        // use all remaining parts in the DSN
        foreach ($dsn as $key => $val) {
            $dsn[$key] = "{$key}={$val}";
        }
        return $this->_pdoType . ':' . implode(';', $dsn);
    }

Usage Example

Example #1
0
 /**
  * Override _dsn() and ensure that charset is incorporated in mysql
  * @see Zend_Db_Adapter_Pdo_Abstract::_dsn()
  */
 protected function _dsn()
 {
     $dsn = parent::_dsn();
     if (isset($this->_config['charset'])) {
         $dsn .= ';charset=' . $this->_config['charset'];
     }
     return $dsn;
 }