Location: PHPKode > scripts > BackItUp > backitup/backup_all.php
<?php

/****************************************************************
*	BackItUp by Eirik Opsanger (hide@address.com)				*
*	Please contact me if you find any bugs or need help!		*
****************************************************************/		

//DO NOT change anyting in this file!
$data = ("
		#################
		##BackItUp by Eirik Opsanger (january 2005)
		##
		##Backupdate: ".date(d).".".date(m).".".date(Y)."
		##Database: $db
		#################\n
");


$tabeller = mysql_list_tables("$db");
$tab_navn = array();
for ($i = 0; $i < mysql_num_rows($tabeller); $i++) {
     $tab_navn[] = mysql_tablename($tabeller, $i);
}

foreach ($tab_navn as $tabell) {
$query = mysql_query("SHOW CREATE TABLE $tabell");
$result = mysql_fetch_array($query);

$data .= ("DROP TABLE IF EXISTS $tabell**\n");
$data .= ("$result[1]**\n\n");

	$felt_navn = array();
	$query = mysql_query('SELECT * FROM '.$tabell);
	for ($i = 0; $i < mysql_num_fields($query); $i++) {
    	$felt_navn[] = mysql_field_name($query, $i);
	}
	
	while($result = mysql_fetch_array($query)) {
		$data .= ("INSERT INTO `$tabell` VALUES (");
		foreach ($felt_navn as $felt_name) {
			$result[$felt_name] = str_replace("'", "\'", $result[$felt_name]);
			$data .= ("'$result[$felt_name]'");
			if(next($felt_navn)) {
				$data .= (", ");
			}
		}	
		$data .= (")**\n");
	}
	mysql_free_result($query);
}
$data .= ("\n");

$filnavn = time().'_-_'.$db.'_-_struk_-_data.inc';

    if (!$action = fopen('files/'.$filnavn, 'w')) {
         print("Can not open $filnavn");
    } elseif (fwrite($action, $data) === FALSE) {
        print("Can not write to $filnavn");
    } else {
    
    print("<center>Backup of <i>$db</i> successfull!</center><br>");
 	}     
 	fclose($action);
 	
 	?>
Return current item: BackItUp