0

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.

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 Altervista).

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?

The former script was something like this

$table_top = "<table class=\"tab\">";
$table_bottom = "</table>";
$mail="<html><body>";
$add="[email protected]";
$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.="<h2>table: ".$table."</h2>";
    $query2 = "DESCRIBE $table"; 
    $result2 = mysql_query($query2);
    $mail.=$table_top;
    $mail.="<tr><th>Field</th><th>Type</th><th>Null</th><th>Key</th><th>Default</th><th>Extra</th><tr>";
    while($row2 = mysql_fetch_row($result2)){
        $k2=count($row2);
        $mail.="<tr>";
        for($i2=0; $i2<$k2; $i2++){
            $mail.="<td>".$row2[$i2]."</td>";
        }
        $mail.="</tr>";
    }
    $mail.=$table_bottom."<br><br>";
    $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.="<br>";
    }
}
$mail.="</body></html>";
mail($add,$tit,$mail,$headers);

Thanks guys! :)

9
  • 1
    If anything changed on the server, it's the PHP version. Add error reporting to the top of your file(s) right after your opening <?php tag error_reporting(E_ALL); ini_set('display_errors', 1); see if it yields anything. You may get a deprecation warning. If so, you will need to switch to mysqli or PDO. Commented Dec 9, 2014 at 14:48
  • 2
    You may have gotten caught - Here is an example of what happens when you continue to use mysql_* functions. Learn about prepared statements instead, and use PDO or MySQLi. This article will help you decide. Commented Dec 9, 2014 at 14:49
  • @JayBlanchard Good day Jay ;) long time no see. Commented Dec 9, 2014 at 14:50
  • This library may helpful to you.I feel it's more reliable. github.com/ifsnop/mysqldump-php Commented Dec 9, 2014 at 14:50
  • 1
    See this Q&A's on Stack stackoverflow.com/q/8166277 - You can further your research on Google using what I used for keywords to find that "backup database and download .sql file php". Use a header. Commented Dec 9, 2014 at 16:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.