Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP+SQL]Backup bazy z poziomu php, Czy jest jakies ale?
marcio
post 9.11.2008, 19:29:11
Post #1





Grupa: Zarejestrowani
Postów: 2 291
Pomógł: 156
Dołączył: 23.09.2007
Skąd: ITALY-MILAN

Ostrzeżenie: (10%)
X----


EDIT
Ok dla wszystkich tych ktory nie wiedza jak zrobic a maja taka potrzebe:
  1. <?php
  2. function create_backup_file($file_name_backup, $drop = false) {
  3.  
  4.            $file = fopen($file_name_backup, 'w+');
  5.            
  6.            $output = "# Czas wygenerowania: ".date('d-m-Y G:i')."r\n";
  7.            $output .= "# Wersja serwera: ".mysql_get_server_info()."r\n";
  8.            $output .= "# Wersja php: ".phpversion()."r\nr\n";
  9.            fwrite($file, $output);
  10.  
  11.            $query = 'SHOW TABLES';
  12.            $result = mysql_query($query);
  13.            while ($row = mysql_fetch_assoc($result)) foreach ($row as $table) {
  14.  
  15.            $struct_table[$table] = '';
  16.            $struct_table[$table] .= "r\nr\n# Struktura tabeli: ".$table."r\nr\nr\n";
  17.  
  18.            $query_struct_table = mysql_query("SHOW CREATE TABLE `$table`");
  19.            while($struct = mysql_fetch_row($query_struct_table)) {
  20.  
  21.             foreach($struct as $tbl)
  22.  
  23.               if($drop) {
  24.              
  25.               $struct_table[$table] .= 'DROP TABLE IF EXISTS `'.$table."`;r\n";
  26.               $struct_table[$table] .= $tbl. ";r\nr\n";
  27.             }
  28.             else $struct_table[$table] .= $tbl. ";r\nr\n";
  29.          }
  30.            
  31.            fwrite($file, $struct_table[$table]);
  32.  
  33.            $table_zaw = "-------------------------------r\n";
  34.            $table_zaw .= '- Zawartosc tabeli: '.$table."r\n";
  35.            $table_zaw .= "-------------------------------r\nr\nr\n";              
  36.  
  37.                fwrite($file, $table_zaw);
  38.                $result2 = mysql_query('SHOW COLUMNS FROM '.$table);
  39.                $col_names= '';
  40.  
  41.                while($row = mysql_fetch_array($result2)) $col_names .= "`$row[0]`".', ';
  42.  
  43.                $col_names = substr($col_names, 0, -2);
  44.                $result2 = mysql_query('SELECT * FROM '.$table);
  45.                $num = mysql_num_fields($result2);
  46.  
  47.                while($row2 = mysql_fetch_row($result2)) {
  48.  
  49.                    $values = '';
  50.                    for($i = 0; $i < $num; $i++) {
  51.  
  52.                     $type = mysql_field_type($result2, $i);
  53.                      if($type == "tinyint" || $type == "smallint" || $type == "mediumint" || $type == "int" || $type == "bigint" || $type == "timestamp") $values.= $row2[$i].', '; else $values .= "'$row2[$i]'".', ';
  54.                    }
  55.                    $values = substr($values, 0, -2);
  56.                    $insert = "INSERT INTO ".$table."(".$col_names.") VALUES(".$values.");r\n";
  57.                    fwrite($file, trim($insert, "\n"));
  58.                }
  59.            }
  60.            fclose($file);
  61. }
  62.  
  63.  
  64. function download_file($file_backup) {
  65.  
  66.            header('Content-type: application/x-unknown');
  67.            header('Content-Disposition: attachment; filename='.$file_backup);
  68.            header('Connection: close');
  69.            header('Expires: 0');
  70.            readfile($file_backup);
  71. }
  72. ?>

Jedyne co to dubluje jeszcze nazwe tabeli i nie wiem nadal dlaczego.

Tak wyglada kawalek zrzutu: http://wklej.org/id/16542/

Ten post edytował marcio 9.11.2008, 20:04:00


--------------------
Zainteresowania: XML | PHP | MY(SQL)| C# for .NET | PYTHON
http://code.google.com/p/form-builider/
Moj blog
Go to the top of the page
+Quote Post

Posty w temacie
- marcio   [PHP+SQL]Backup bazy z poziomu php   9.11.2008, 19:29:11


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 19:06