break; } //make file header $sqlFile = "--\n"; $sqlFile .= "-- SQL DUMP " . date('Y.m.d @ H:i') . "\n"; $sqlFile .= "-- Calendar: {$dbSet['calendarTitle']}\n"; $sqlFile .= "-- Database: {$dbDir}{$calID}.cdb\n"; $sqlFile .= "--\n"; $sqlFile .= "-- LuxCal version: {$lcV}\n"; $sqlFile .= "-- http://www.luxsoft.eu\n"; $sqlFile .= "--\n\n"; //backup tables foreach ($tables as $table) { $sqlFile .= "\n-- " . str_repeat("=", 56) . "\n\n--\n-- Table {$table}\n--\n\n"; $sqlFile .= "DROP TABLE IF EXISTS `{$table}`;\n\n"; $sqlFile .= getTableSql($table) . ";\n\n"; //get SQL code to create table $stH = dbQuery("SELECT * FROM `{$table}`"); while ($row = $stH->fetch(PDO::FETCH_NUM)) { $sqlFile .= "INSERT INTO `{$table}` VALUES("; foreach ($row as $value) { $sqlFile .= isset($value) ? "'" . addslashes(preg_replace("%\n%", "\\n", $value)) . "'," : "'',"; } $sqlFile = substr($sqlFile, 0, -1) . ");\n"; //remove last , } $stH = null; //release statement handle! $sqlFile .= "\n"; } //save .sql backup file
function backupDatabase($tables, $echo) { //Create a backup file of the database tables global $ax, $calID, $set, $lcV; //make file header $sqlFile = "--\n"; $sqlFile .= "-- SQL DUMP " . date('Y.m.d @ H:i') . "\n"; $sqlFile .= "-- Calendar: {$set['calendarTitle']}\n"; $sqlFile .= "-- Calendar ID: {$calID}\n"; $sqlFile .= "--\n"; $sqlFile .= "-- LuxCal version: {$lcV}\n"; $sqlFile .= "-- http://www.luxsoft.eu\n"; $sqlFile .= "--\n\n"; //backup tables foreach ($tables as $table) { if ($echo) { echo "{$ax['mdb_backup_table']} '{$table}' - "; } $sqlFile .= "\n-- " . str_repeat("=", 56) . "\n\n--\n-- Table {$table}\n--\n\n"; $sqlFile .= "DROP TABLE IF EXISTS `{$table}`;\n\n"; $sqlFile .= getTableSql($table) . ";\n\n"; //get SQL code to create table $stH = dbQuery("SELECT * FROM `{$table}`"); $counter = 0; while ($row = $stH->fetch(PDO::FETCH_NUM)) { $sqlFile .= "INSERT INTO `{$table}` VALUES ("; foreach ($row as $value) { $sqlFile .= isset($value) ? "'" . str_replace("'", "''", $value) . "'," : "'',"; } $sqlFile = substr($sqlFile, 0, -1) . ");\n"; $counter++; } $stH = null; //release statement handle! $sqlFile .= "\n"; if ($echo) { echo "{$ax['mdb_backup_done']} ({$counter} {$ax['mdb_records']})<br>\n"; } } return $sqlFile; }