title: How can I export MySQL database with a PHP script?
body: <p>I need one script that when I open the <code>script.php</code> page for example, that export me one database from MySQL to an SQL document, and I don't know how to do it in PHP, can some one help me with that?</p>
  
  <p>Edited Code:</p>
  
  <pre><code>&lt;?php
  
  $dbhost   = "localhost";
  $dbuser   = "root";
  $dbpwd    = "";
  $dbname   = "activmanagement";
  $dumpfile = $dbname . "_" . date("Y-m-d_H-i-s") . ".sql";
  
  passthru("D:/wamp/bin/mysql/mysql5.6.17/bin/mysqldump --opt --host=$dbhost --user=$dbuser --password=$dbpwd $dbname &gt; $dumpfile");
  
  // report - disable with // if not needed
  // must look like "-- Dump completed on ..." 
  
  echo "$dumpfile "; passthru("tail -1 $dumpfile");
  
  ?&gt;
  </code></pre>
  
  <p>This line:</p>
  
  <pre><code>passthru("D:/wamp/bin/mysql/mysql5.6.17/bin/mysqldump --opt --host=$dbhost --user=$dbuser --password=$dbpwd $dbname &gt; $dumpfile");
  </code></pre>