Ich hatte auch mal das Problem, dass ich mysqldump nicht verwenden konnte. Damals hatte ich das so gelöst (ist schon älter das script, aus einer alten Klasse herausgenommen: )
PHP-Code:
<?php
function backup($file = '') {
// Erstellt ein komplettes Backup der ausgewählen Datenbank
// Optional kann ein Dateiname angegeben werden, in der das Backup gesichert wird
$dump = '';
// Falls die Verbindung zur Datenbank noch nicht steht wird sie jetzt hergestellt
if($this -> linkid == FALSE)
$this -> connect();
// Nun werden alle Tabellen aus der Datenbank ausgelesen..
$result_a = mysql_query("SHOW TABLES")
or $this -> error('Backup: SHOW TABLES Query fehlgeschlagen');
//.. und das Backup mit den kompletten Daten aus der Tabelle gefüllt
// (dump_table())
while ($row_a = mysql_fetch_row($result_a)) {
$dump .= $this -> dump_table($row_a[0]);
}
// Falls gewünscht wird nun das Backup in eine Datei geschrieben
if(empty($file) == FALSE) {
@chmod($file, 0777);
$fp = @fopen($file, 'w');
if($fp == FALSE)
$this -> error('Backup: Konnte die Datei für das Backup nicht anlegen');
fwrite($fp, $dump);
fclose($fp);
}
return $dump;
}
// ...
function dump_table($table) {
@mysql_query("LOCK TABLE $table WRITE")
or $this -> error('Backup: Konnte die Tabelle ' . $table . ' nicht sperren');
$temp = @mysql_fetch_assoc(@mysql_query("SHOW CREATE TABLE $table"))
or $this -> error('Backup: SHOW CREATE TABLE ' . $table . ' Query fehlgeschlagen');
$dump = "DROP TABLE IF EXISTS $table;\r\n" . str_replace("\n", '', $temp['Create Table']) . ";\r\n";
$result = mysql_query("SELECT * FROM $table")
or $this -> error('Backup: SELECT * FROM ' . $table . ' fehlgeschlagen');
while ($row = mysql_fetch_assoc($result)) {
$fields = '(';
$values = '(';
foreach ($row as $key => $value) {
$fields .= mysql_escape_string($key).", ";
$values .= "'".mysql_escape_string($value)."', "; // was ist mit NULL?
}
$fields = substr($fields, 0, -2).")";
$values = substr($values, 0, -2).")";
$dump .= "INSERT INTO $table $fields VALUES $values;\r\n";
}
mysql_query("UNLOCK TABLES")
or $this -> error('Backup: Konnte die Tabelle ' . $table . ' nicht entsperren');
return $dump."\n";
}
?>
Musst du eben noch ein bisschen an deine Vorstellungen anpassen.
Basiert übrigens auf
http://phpfriend.de/forum/ftopic32995.html