<?php

//nclude "header.php";

?>

<style type="text/css">

<!--

.style1 {

	color: #FFFFFF;

	font-weight: bold;

}

.style3 {font-size: 18}

.style4 {color: #FF0000}

.style5 {font-size: 18; color: #FF0000; }

-->

td{

	font-family:Verdana, Geneva, sans-serif;}

</style>





<?php

backup_tables('localhost','mdsoftwareco_rns','w&S8zzGMx]QI','mdsoftwareco_rns');





/* backup the db OR just a table */

function backup_tables($host= 'localhost',$user= 'mdsoftwareco_rns',$pass= 'w&S8zzGMx]QI',$name= 'mdsoftwareco_rns',$tables = 'mdsoftwareco_rns')

{

	

	$link = mysql_connect($host,$user,$pass);

	mysql_select_db($name,$link);

	

	//get all of the tables

	if($tables == 'mdsoftwareco_rns')

	{

		$tables = array();

		$result = mysql_query('SHOW TABLES');

		while($row = mysql_fetch_row($result))

		{

			$tables[] = $row[0];

		}

	}

	else

	{

		$tables = is_array($tables) ? $tables : explode(',',$tables);

	}

	

	//cycle through

	foreach($tables as $table)

	{

		$result = mysql_query('SELECT * FROM '.$table.'where code='$code'');

		$num_fields = mysql_num_fields($result);

		

		$return.= 'DROP TABLE '.$table.';';

		$row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));

		$return.= "\n\n".$row2[1].";\n\n";

		

		for ($i = 0; $i < $num_fields; $i++) 

		{

			while($row = mysql_fetch_row($result))

			{

				$return.= 'INSERT INTO '.$table.' VALUES(';

				for($j=0; $j<$num_fields; $j++) 

				{

					$row[$j] = addslashes($row[$j]);

					$row[$j] = ereg_replace("\n","\\n",$row[$j]);

					if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }

					if ($j<($num_fields-1)) { $return.= ','; }

				}

				$return.= ");\n";

			}

		}

		$return.="\n\n\n";

	}

	

	$day=date("d");

	$month=date("m");

	$year=date("Y");

	$time_now=mktime(date('H')+5,date('i')+30,date('s'));

$time_noww=date('H_i_s',$time_now);

$handle = fopen('backup_database/db-backup-(-'.$year.'-'.$month.'-'.$day.'-)----{-'.$time_noww.'-}----'.time().'-'.(md5(implode(',',$tables))).'.sql','w+');

$handlex = 'backup_database/db-backup-(-'.$year.'-'.$month.'-'.$day.'-)----{-'.$time_noww.'-}----'.time().'-'.(md5(implode(',',$tables))).'.sql';

?>



<?php $handlee = fwrite($handle,$return);

fclose($handle);

?><table width="80%" border="0" cellspacing="2" cellpadding="2" align="center" >

  <tr>

    <td bgcolor="#990000" style="color:#FFFFFF; font-size:16px; font-weight:bold;"><?php if($handlee!=""){

?>Successfully Save Data On Server</center><?php };?></td>

  </tr>

  <tr>

    <td bgcolor="#FFFF00"><div align="center" style="font-size:18px"><strong>Backup File Path</strong></div></td>

  </tr>

  <tr>

    <td><div align="center" class="style3"><a href="<?php echo $handlex; ?>" target="_blank" class="style4" style="font-size:18px; font-family:Verdana, Geneva, sans-serif"><?php echo $handlex; ?></a></div></td>

  </tr>

  <tr>

    <td bgcolor="#FFFF00"><div align="center" style="font-size:18px"><strong>Backup Date</strong></div>

    <div align="left"></div></td>

  </tr>

  <tr>

    <td><div align="center" class="style3 style4" style="font-size:18px"><?php echo $day; ?>-<?php echo $month; ?>-<?php echo $year; ?></div></td>

  </tr>

  <tr>

    <td bgcolor="#FFFF00"><div align="center" style="font-size:18px"><strong>Backup Time</strong></div>

    <div align="left"></div></td>

  </tr>

  <tr>

    <td><div align="center" class="style5" style="font-size:18px"><?php echo $time_noww; ?></div></td>

  </tr>

</table>

<?php

}

?>

<?php



//include "footer.php";



?>

