title: PHP script to download MySQL backup
body: <p>I need your help. For my website, I was using a simple PHP script that was creating an email with the description of my database and all the data in it, and it was sending it to my email once I clicked on a special link on the admin page.</p>
  
  <p>Suddenly it does not work anymore, probably because the web server on which I uploaded the site has changed some parameters, which I cannot customize (I'm working on <a href="http://altervista.org/" rel="nofollow">Altervista</a>).</p>
  
  <p>Do you have any idea of how to create a script that allows me to download the same backup by clicking on the same link, instead of receiving an email?</p>
  
  <p>The former script was something like this</p>
  
  <pre><code>$table_top = "&lt;table class=\"tab\"&gt;";
  $table_bottom = "&lt;/table&gt;";
  $mail="&lt;html&gt;&lt;body&gt;";
  $add="whatever@example.com";
  $tit="Backup MySQL (".date("d-m-Y, H:i",time()).")";
  $headers="Content-type: text/htmlrn";
  
  $query = "SHOW TABLES FROM my_database"; 
  $result = mysql_query($query);
  while($row = mysql_fetch_row($result)){
      $table = $row[0];
      $mail.="&lt;h2&gt;table: ".$table."&lt;/h2&gt;";
      $query2 = "DESCRIBE $table"; 
      $result2 = mysql_query($query2);
      $mail.=$table_top;
      $mail.="&lt;tr&gt;&lt;th&gt;Field&lt;/th&gt;&lt;th&gt;Type&lt;/th&gt;&lt;th&gt;Null&lt;/th&gt;&lt;th&gt;Key&lt;/th&gt;&lt;th&gt;Default&lt;/th&gt;&lt;th&gt;Extra&lt;/th&gt;&lt;tr&gt;";
      while($row2 = mysql_fetch_row($result2)){
          $k2=count($row2);
          $mail.="&lt;tr&gt;";
          for($i2=0; $i2&lt;$k2; $i2++){
              $mail.="&lt;td&gt;".$row2[$i2]."&lt;/td&gt;";
          }
          $mail.="&lt;/tr&gt;";
      }
      $mail.=$table_bottom."&lt;br&gt;&lt;br&gt;";
      $query2 = "SELECT * FROM $table"; 
      $result2 = mysql_query($query2);
      while($row2 = mysql_fetch_row($result2)){
          $mail.="\"".$row2[0]."\"";
          $i=1;
          while(isset($row2[$i])){
              $mail.=","."\"".$row2[$i]."\"";
              $i=$i+1;
          }
          $mail.="&lt;br&gt;";
      }
  }
  $mail.="&lt;/body&gt;&lt;/html&gt;";
  mail($add,$tit,$mail,$headers);
  </code></pre>
  
  <p>Thanks guys! :)</p>