Location: PHPKode > scripts > BackItUp > backitup/data_backup.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
");


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


foreach ($tab_navn as $tab_name) {
	$data .= ("###\n##Data for $tab_name\n###\n");
	$felt_navn = array();
	$query = mysql_query('SELECT * FROM '.$tab_name);
	
	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 `$tab_name` 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.'_-_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>Data-backup of <i>$db</i> was successfull!!</center><br>");
 	}     
 	fclose($action);

?> 
Return current item: BackItUp