<?php 
include ('ayar.php'); 


// Backup Settings 
$filename = date(d.'_'.m.'_'.Y); 
$filename = $filename.".sql"; 

 
    $tables = mysql_list_tables($database); 
    $tablenumb = mysql_num_rows($tables);
    $yedek.=''; 
    for ($a=0;$a<$tablenumb;$a++) { 
        $row=mysql_fetch_row($tables); 
        $tablename=$row[0]; 
        $crtable = mysql_query("show create table $tablename"); 
        $tmpres = mysql_fetch_row($crtable); 
            $yedek. "\n\n"; 
            $yedek. $tmpres[1].";"; 
            $yedek. "\n\n"; 
        $lines = mysql_query("select * from `$tablename`"); 
        $linenumb = mysql_num_fields($lines); 
        $nr = mysql_num_rows($lines); 
        for ($c=0;$c<$nr;$c++) { 
            $yedek. "INSERT INTO `$tablename` VALUES ("; 
            $row = mysql_fetch_row($lines); 
            $yedek. ($d=0;$d<$linenumb;$d++) { 
        $data = strval($row[$d]); 
            $yedek. "'".addslashes($data)."'"; 
                if ($d<($linenumb-1)) { 
                    $yedek. ", "; 
                } 
                    } 
                    $yedek. ");\n"; 
            } 
         
         }
         
        // Normal Dosya yazmak için
         
         $yedekdosyasi=fopen($filename,'w+');
         fwrite($yedekdosyasi,$yedek);
         fclose($yedekdosyasi);
         
         
         // gz yazmak için
         
         $yedekdosyasi=gzopen($yedekdosyasi.'.gz','w+');
         gzwrite($yedekdosyasi,$yedek);
         gzclose($yedekdosyasi);
         
         
         
         // oluşturduktan sonra indirmek için
         
         header('Location:'.$yedekdosyasi);
         
          
?>