Advertisement
GWibisono

break yg bikin mumet

May 14th, 2015
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.15 KB | None | 0 0
  1. <?php
  2. $aksi=isset($_GET['aksi']) ? $_GET['aksi'] : "";
  3. switch($aksi){
  4. default:   
  5.     $waktu=date("DdMY");
  6.     echo"<div class='content_block'><div class='box_bg'><h2>Backup Database</div></div><div class='content_block'><div class='box_bg'>";
  7.     if(!isset($_GET['tabel']))$tables='semua';
  8.     else $tables=$_GET['tabel'];
  9.         if($tables == 'semua'){
  10.             $tables = array();
  11.             $result = mysql_query('SHOW TABLES');
  12.             while($row = mysql_fetch_row($result)){
  13.             $tables[] = $row[0];
  14.             $return.= 'DROP TABLE IF EXIST IF EXIST '.$table.';';}
  15.         }else{
  16.             //jika hanya table-table tertentu
  17.             $tables = is_array($tables) ? $tables : explode(',',$tables);
  18.         }
  19.         //looping dulu ah
  20.             $return="";
  21.             foreach($tables as $table){
  22.             $result = mysql_query('SELECT * FROM '.$table);
  23.             $num_fields = mysql_num_fields($result);
  24.             //menyisipkan query DROP TABLE IF EXIST untuk nanti hapus table yang lama
  25.             $return.= 'DROP TABLE IF EXIST '.$table.';';
  26.             $row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
  27.             $return.= "".$row2[1].";";
  28.             for ($i = 0; $i < $num_fields; $i++){
  29.                 while($row = mysql_fetch_row($result)){
  30. /*                 
  31. menyisipkan query Insert. untuk nanti memasukan data yang lama ketable yang baru dibuat. so toy mode : ON
  32. */
  33.                     $return.= 'INSERT INTO '.$table.' VALUES(';
  34.                     for($j=0; $j<$num_fields; $j++){
  35.                     //akan menelusuri setiap baris query didalam
  36.                         $row[$j] = $row[$j];
  37.                         if (isset($row[$j])) {
  38.                             $return.= '"'.addslashes($row[$j]).'"' ;
  39.                         }
  40.                         else {
  41.                             $return.= '""';
  42.                         }
  43.                         if ($j<($num_fields-1)) {
  44.                             $return.= ',';
  45.                         }
  46.                     }
  47.                     $return.= ");\n";
  48.                 }
  49.             }
  50.                 $return.="\n\n";
  51.         }
  52.     $tabel=array("ppdb_admin", "ppdb_pendaftar", "ppdb_info","ppdb_kontak","ppdb_menu","ppdb_submenu","ppdb_siswa","ppdb_clnsiswa","ppdb_prestasi","ppdb_nilai");
  53.     echo"<form  name='form-backup' method='post' action='?module=backup&aksi=backup'>
  54.     Pilih tabel <select name='tabel' onChange=\"window.location.href='?module=backup&tabel='+this.value;\">
  55.         <option value='semua'>semua tabel</option>";
  56.         $table=isset($_GET['tabel']) ? $_GET['tabel'] : "semua";
  57.         foreach($tabel as $tbl){
  58.             echo"<option value='$tbl'";
  59.             if($tbl==$table) echo" selected";
  60.             echo">$tbl</option>";
  61.         }
  62.     echo "</select>
  63.     <textarea name='isitabel' style='width: 100%;' cols=83 rows=25>".htmlentities($return)."</textarea><br>
  64.     <input type=submit class='tombol' value='Backup'></form>";
  65.     echo"</div></div>";
  66. break;
  67. case "backup":
  68.     $nama_file=date("DdMY").'_backup_data_'.time().'.sql';
  69.     $return=$_POST['isitabel'];
  70.         $nama_file;
  71.         $handle = fopen('backup/'.$nama_file,'w+');
  72.         fwrite($handle, stripslashes($return) );
  73.         fclose($handle);
  74.     echo "Database berhasil dibackup, untuk mendownload file backup klik tombol berikut!<br><br>
  75.         <a class='tombol' href='modul/mod_br/backup/backup.php?aksi=download&file=$nama_file'>Download File Backup</a>";
  76. break;
  77. case "download":
  78.     $folder="../../../backup/";
  79.     $file=$_GET['file'];
  80.     header("Content-Disposition: attachment; filename=$folder".$file);
  81.     header("Content-type: $folder".$file);
  82.     readfile("$folder".$file);
  83.     unlink("$folder$file");
  84.     exit;
  85. break;
  86. }
  87. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement