LazyRecord\Connection::getDSN PHP Method

getDSN() public method

public getDSN ( )
    public function getDSN()
    {
        if ($this->dsn) {
            return $this->dsn;
        }
        $parser = new DSNParser();
        return $this->dsn = $parser->parse($this->config['dsn']);
    }

Usage Example

Beispiel #1
0
 public function backupToDatabase(Connection $source, $databaseName, $dropAndCreate = false)
 {
     $newDSN = clone $source->getDSN();
     if ($newDSN->getAttribute('dbname') == $databaseName) {
         throw new LogicException('Backup to the same database.');
     }
     if ($dropAndCreate) {
         $source->query('DROP DATABASE IF EXISTS ' . $databaseName);
         $source->query('CREATE DATABASE IF NOT EXISTS ' . $databaseName . ' CHARSET utf8');
     }
     // Create new dest database connection
     $newConfig = $source->getConfig();
     $newDSN->setAttribute('dbname', $databaseName);
     $newConfig['dsn'] = $newDSN->__toString();
     $dest = Connection::create($newConfig);
     return $this->backup($source, $dest);
 }