"; print ""; print "$msg[529]"; print ""; // initialisation if(!empty($file)) { @set_time_limit(0); $dump_buffer = ''; // définition du retour chariot $crlf = "\n"; $db = "bibli"; $today = date("d/m/Y H:i:s"); $separator = "# ------------------------------------$crlf"; // construction du dump $tables = mysql_list_tables($db); $num_tables = @mysql_num_rows($tables); // en-tête $dump_buffer .= "$separator# pmb MySQL-Dump$crlf"; $dump_buffer .= "# $today$crlf"; $dump_buffer .= "# backup base \"$db\"$crlf"; $dump_buffer .= $separator.$crlf; $i = 0; while($i < mysql_num_rows($tables)) { $table[$i] = mysql_tablename($tables, $i); $i++; } while(list($cle, $valeur)=each($table)) { $requete = "SHOW CREATE TABLE $valeur"; $result = mysql_query($requete, $dbh); $create = mysql_fetch_row($result); // écriture de la méthode de création $dump_buffer .= "$crlf$separator# structure de la table $valeur$crlf$separator$crlf"; $dump_buffer .= "DROP TABLE IF EXISTS ".$valeur.";$crlf"; $dump_buffer .= $create[1].";$crlf"; $dump_buffer .= "$crlf$separator# contenu de la table $valeur$crlf$separator$crlf"; // écriture des données $requete = "SELECT * FROM $valeur"; $result = mysql_query($requete, $dbh); $nbr_lignes = mysql_num_rows($result); $field_set = ""; $field = ""; for($i = 0; $i < $nbr_lignes; $i++) { $row = mysql_fetch_row($result); // on regarde si le champ est un entier for ($j=0; $j < mysql_num_fields($result); $j++) { $field_set[$j] = mysql_field_name($result, $j); $type = mysql_field_type($result, $j); if ($type=='tinyint'||$type=='smallint'||$type=='mediumint'||$type=='int'||$type=='bigint'||$type=='timestamp') { $field[$j] = $row[$j]; } else { $field[$j] = "'".addslashes($row[$j])."'"; } } $fields = implode(', ', $field_set); $content = implode(', ', $field); $dump_buffer .= "INSERT INTO ".$valeur." ($fields) VALUES ($content);$crlf"; } } $file = "./tables/".$file.".sql"; @set_time_limit(0); // timeout illimité // écriture du fichier $fp = @fopen($file, 'wb'); if($fp) { $result = @fwrite($fp, $dump_buffer); if($result) { $size = number_format($result/1024,2); print "$msg[528]
$file : $size Ko écrits"; } else { user_error_message(2); } fclose($fp); } else { user_error_message(2); } } else { ?>
$msg[531]
"; print $backup_form; } ?>