MySQLDump::save PHP Method

save() public method

Saves dump to the file.
public save ( $file ) : void
return void
    public function save($file)
    {
        $handle = strcasecmp(substr($file, -3), '.gz') ? fopen($file, 'wb') : gzopen($file, 'wb');
        if (!$handle) {
            throw new Exception("ERROR: Cannot write file '{$file}'.");
        }
        $this->write($handle);
    }

Usage Example

 /**
  * @param string $fileNamePrefix
  * @param bool $removeBackupFileAtTheEnd
  * @throws \Exception
  * @throws IOException
  * @return ResultObject[]
  */
 public function backup($fileNamePrefix = null, $removeBackupFileAtTheEnd = false)
 {
     $storagePath = $this->prepareStoragePath($this->backupTempPath);
     $file = new DatabaseBackupFile($storagePath);
     if (!empty($fileNamePrefix)) {
         $file->setNamePrefix($fileNamePrefix);
     }
     $this->mysqlDump->save($file->getFilePath());
     $resultObjects = [];
     /** @var IDatabaseBackupHandler $handler */
     foreach ($this->backupHandlers as $handler) {
         $results = $handler->process($file);
         $resultObjects = array_merge($resultObjects, $results);
     }
     if ($removeBackupFileAtTheEnd === true) {
         $this->removeBackupFile($file);
     }
     return Arrays::flatten($resultObjects);
 }
All Usage Examples Of MySQLDump::save