Revision 190
Added by ryan about 19 years ago
trunk/wb/modules/backup/backup-sql.php | ||
---|---|---|
46 | 46 |
$result = $database->query("SHOW TABLE STATUS"); |
47 | 47 |
|
48 | 48 |
// Loop through tables |
49 |
while($row = $result->fetchRow()) { |
|
50 |
$query = $database->query("SHOW CREATE TABLE ".$row['Name']); |
|
51 |
$sql_backup = "\r\n# Create table ".$row['Name']."\r\n\r\n"; |
|
49 |
while($row = $result->fetchRow()) { |
|
50 |
//show sql query to rebuild the query |
|
51 |
$sql = 'SHOW CREATE TABLE '.$row['Name'].''; |
|
52 |
$query2 = $database->query($sql); |
|
52 | 53 |
// Start creating sql-backup |
53 |
$out = $query->fetchRow();
|
|
54 |
$sql_backup .= $out['Create Table'].";\r\n\r\n";
|
|
55 |
$sql_backup .= "# Dump data for ".$row['Name']."\r\n\r\n";
|
|
56 |
$sql = "SELECT * FROM ".$row['Name'];
|
|
57 |
// SQL code to select everything
|
|
58 |
$out = $database->query($sql);
|
|
54 |
$sql_backup ="\r\n# Create table ".$row['Name']."\r\n\r\n";
|
|
55 |
$out = $query2->fetchRow();
|
|
56 |
$sql_backup.=$out['Create Table'].";\r\n\r\n";
|
|
57 |
$sql_backup.="# Dump data for ".$row['Name']."\r\n\r\n";
|
|
58 |
// Select everything |
|
59 |
$out = $database->query('SELECT * FROM '.$row['Name']);
|
|
59 | 60 |
$sql_code = ''; |
60 |
while($code = $out->fetchRow()) {
|
|
61 |
// Loop trough all collumns
|
|
62 |
$sql_code .= "INSERT INTO ".$row['Name']." SET "; |
|
61 |
// Loop through all collumns
|
|
62 |
while($code = $out->fetchRow()) {
|
|
63 |
$sql_code .= "INSERT INTO ".$row['Name']." SET ";
|
|
63 | 64 |
$numeral = 0; |
64 |
foreach($code as $insert => $value) { |
|
65 |
foreach($code as $insert => $value) { |
|
66 |
// Loosing the numerals in array -> mysql_fetch_array($result, MYSQL_ASSOC) WB hasn't? |
|
65 | 67 |
if($numeral==1) { |
66 |
// Loosing the numerals in array -> mysql_fetch_array($result, MYSQL_ASSOC) WB hasn't? |
|
67 |
$sql_code.= $insert." = '".addslashes($value)."',"; |
|
68 |
$sql_code.=$insert ."='".addslashes($value)."',"; |
|
68 | 69 |
} |
69 | 70 |
$numeral = 1 - $numeral; |
70 | 71 |
} |
71 | 72 |
$sql_code = substr($sql_code, 0, -1); |
72 | 73 |
$sql_code.= ";\r\n"; |
73 |
$output .= $sql_backup.$sql_code; |
|
74 | 74 |
} |
75 |
$output .= $sql_backup.$sql_code; |
|
75 | 76 |
} |
76 | 77 |
|
77 | 78 |
// Output file |
Also available in: Unified diff
backup-sql.php now fully working