Location: PHPKode > scripts > MySQL Dump > mysql-dump/dump.php
<head>
<meta name="ROBOTS" content="noINDEX, noFOLLOW">
<title>MySQL Backupmodul by Transatlantic-Web</title>
</head>
<?php 
/*******************************************/
/* MySQL Datenbankbackup                   */
/* Modul "dump.php"                        */
/* Version 1.0 , GNU TAW24 Germany         */
/* Author Transatlantic-Web                */
/* http://www.taw24.de                     */
/*                                         */
/* modified by benjamin klatt              */
/*  <hide@address.com>           */
/*******************************************/

//  -------------------------------------------------------------------------------------
include ("dump_cfg.inc");
include ("lang_" .$lang.".inc");

echo "<font size=+1><b>".$title."</b><br>Servername: '".$host."'</font><br>";
echo $system.php_uname().$phpversion.phpversion(). "<p>";

// Alle Datenbanken auf dem Server suchen
echo "<table border=1>";
echo "<tr><td><b>".$dbname."</b></td><td><b>".$tcount."</b></td><td><b>".$size."</b></td><td><b>".$status."</b></td></tr>";
echo "<tr><td>&nbsp;&nbsp;$db1</td>";
 $database = $db1;
 $zaehler = 0;
 $start=0;


// generate filesuffix if it should be used
if($use_date == 1)
{
	$datum = "_".date(dmY);	
}
else
{
	$datum = "";	
}

 $file_name = $path.$database.$datum.".sql";
 $file_old = $path.$database.".old";
 $aktime=date("d-m-Y H:i");
 $db_name = $dump1."$aktime\n";
 $db_name.= $dump2."$database \r\n";
 if (file_exists($file_name)){unlink($file_name);}  
 $fd = fopen($file_name,"a+");
 fwrite($fd, $db_name); 
 fclose($fd);     
 
// Tabellenname Array auslesen und aufbauen

$tbl_array = array(); $c = 0;
$result2 = mysql_list_tables($database);
for($x=0; $x<mysql_num_rows($result2); $x++) 
{ 	
		$tabelle = mysql_tablename($result2,$x);
		 if ($tabelle <>"") {
	  						$tbl_array[$c] = mysql_tablename($result2,$x); $c++;$zaehler++;
							 }

}								 
echo "<td align=right>&nbsp;".$zaehler."&nbsp;&nbsp;</td>";
flush();
// Start Ausgabe und Berechnung 
for ($y = 0; $y < $c; $y++){  
	$tabelle=$tbl_array[$y];

// Struktur der Tabelle einlesen

    $def = "";
    $def .= "DROP TABLE IF EXISTS $tabelle; \n";
    $def .= "CREATE TABLE $tabelle (\n"; 
    $result3 = mysql_db_query($database, "SHOW FIELDS FROM $tabelle",$conn_id);
    while($row = mysql_fetch_array($result3)) {
        $def .= "    $row[Field] $row[Type]";
        if ($row["Default"] != "") $def .= " DEFAULT '$row[Default]'";
        if ($row["Null"] != "YES") $def .= " NOT NULL";
       	if ($row[Extra] != "") $def .= " $row[Extra]";
        	$def .= ",\n";
     }
     $def = ereg_replace(",\n$","", $def);
     $result3 = mysql_db_query($database, "SHOW KEYS FROM $tabelle",$conn_id);
     while($row = mysql_fetch_array($result3)) {
          $kname=$row[Key_name];
          if(($kname != "PRIMARY") && ($row[Non_unique] == 0)) $kname="UNIQUE|$kname";
          if(!isset($index[$kname])) $index[$kname] = array();
          $index[$kname][] = $row[Column_name];
     }
     while(list($xy, $columns) = @each($index)) {
          $def .= ",\n";
          if($xy == "PRIMARY") $def .= "   PRIMARY KEY (" . implode($columns, ", ") . ")";
          else if (substr($xy,0,6) == "UNIQUE") $def .= "   UNIQUE ".substr($xy,7)." (" . implode($columns, ", ") . ")";
          else $def .= "   KEY $xy (" . implode($columns, ", ") . ")";
     }

     $def .= "\n); \n";
     
// Ende Struktur Modul
$db = @mysql_select_db($database,$conn_id); 

$tabelle="".$tabelle; 
$ergebnis=array();
$tbl_name = $dump3."$tabelle \r\n"; 
$fd = fopen($file_name,"a+"); 
fwrite($fd, $tbl_name.$def); 
fclose($fd);

	unset($data);
if ($tabelle>""){  
    $ergebnis[]=@mysql_select_db($database,$conn_id); 
    $result=mysql_query("select * from $tabelle"); 
        $anzahl= mysql_num_rows ($result); 
    $spaltenzahl = mysql_num_fields($result); 
        for ($i=0;$i<$anzahl;$i++) { 
                $zeile=mysql_fetch_array($result); 
        
                $data.="insert into $tabelle ("; 
        for ($spalte = 0; $spalte < $spaltenzahl;$spalte++) { 
              $feldname = mysql_field_name($result, $spalte); 
              if($spalte == ($spaltenzahl - 1)) 
          { 
            $data.= $feldname; 
          } 
          else 
          { 
            $data.= $feldname.","; 
          } 
        }; 
        $data.=") VALUES ("; 
                for ($k=0;$k < $spaltenzahl;$k++){ 
          if($k == ($spaltenzahl - 1)) 
          { 
                        $data.="'".addslashes($zeile[$k])."'"; 
                  } 
          else 
          { 
                        $data.="'".addslashes($zeile[$k])."',"; 
                  } 
        } 
                $data.= ");\n"; 
        } 
$data.= "\n";
} 
else 
{ 
      $ergebnis[]= $err; 
} 

$zeit = (date("d_m_Y")); 
$fd = fopen($file_name,"a+"); 
$zeit = time() - $start;
$speed = $speed+$zeit;

for ($i3=0;$i3<count($ergebnis);$i3++){ 

		fwrite($fd, $data); 
        fclose($fd);	
} 
}
$groesse = filesize($file_name) / 1024;
$place =  $place+$groesse;

echo "<td align=right>&nbsp;&nbsp;<I>".number_format($groesse,2)."</I> KB&nbsp;&nbsp;</td><td align=center> OK! </td></tr>";
echo "</table><p>".$info."<I>".$path."<BR>".$allsize.number_format($place,2)."</I> KB <p>";
echo $copyright;
exit; 
?>

Return current item: MySQL Dump