title: create MySQL dump in pure PHP5
body: <p>I'm creating a backup script for my project, which will be executed via cron.</p>
  
  <p>Right now I'm using:</p>
  
  <pre><code>&lt;?php
  include("config.php");
  
  /* Misc */
  $pathtobackup = realpath('.');
  $backupfolder = realpath("backup");
  $sqlfilename = "SQLDUMP-".date("d-m-Y--H-i").".sql";
  $backupfilename = "BACKUP-".date("d-m-Y--H-i").".zip";
  $backupfilepath = $backupfolder."/".$backupfilename;
  
  /* Systemcall */
  exec("/usr/bin/mysqldump -u{$mysqluser} -p{$mysqlpw} -h {$mysqlserver} {$mysqldb}", $sqldata, $fp);
  
  $sqldump = implode("\n", $sqldata);
  
  if ($fp!=0){
      die("could not create mysql dump\n");
  }
  
  /* Create Zip */
  $zip = new ZipArchive();
  
  if ($zip-&gt;open($backupfilepath, ZIPARCHIVE::CREATE)!==TRUE) {
      die("cannot open &lt;{$backupfilepath}&gt;\n");
  }
  
  
  $path = realpath('.');
  
  $iterator  = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($pathtobackup, FilesystemIterator::SKIP_DOTS));
  
  foreach($iterator as $name=&gt;$object){
  
      $zip-&gt;addFile($name);
  
  }
  
  $zip-&gt;addFromString($sqlfilename, $sqldump);
  
  if ($zip-&gt;close()!==TRUE) {
      die("cannot write &lt;{$backupfilepath}&gt;\n");
  }
  
  ?&gt;
  </code></pre>
  
  <p>But i would like to create the MySQL Dump with pure PHP to make it more compatible and be able to use it on other servers too, where there is no way to use <code>system</code> and <code>mysqldump</code>.</p>
  
  <p>I hope you know a solution with out using an 150 file libary :)</p>
  
  <p>Greetings,
  Frederick</p>