query("SHOW CREATE TABLE `$table`", MYSQLI_USE_RESULT); if (!$res) { echo "-- Error while dumping $table: SHOW CREATE TABLE failed\n"; return; } $line = $res->fetch_row(); $res->free(); $create = FALSE; foreach($line as $item) if (strtoupper(substr(trim($item), 0, 6)) == 'CREATE') { $create = $item; break; } if (!$create) { echo "-- Error while dumping $table: SHOW CREATE TABLE didn't return a usable CREATE TABLE statement\n"; return; } if (defined('DumpStructureOnly')) $create = preg_replace('/\s+AUTO_INCREMENT=\d+/i', '', $create); echo "DROP TABLE IF EXISTS `$table`;\n$create;\n"; if (defined('DumpStructureOnly')) { echo "\n"; return; } // retrieve data from DB $res = $dbConn->query("SELECT * FROM `$table`", MYSQLI_USE_RESULT); if (!$res) { echo "-- Error while dumping $table: SELECT failed\n"; return; } $fields = ""; $fielddesc = $res->fetch_fields(); foreach ($fielddesc as $field) { $fields .= ",`" . $field->name . "`"; } $eol = ""; while (($row = $res->fetch_row())) { if (!$eol) { echo "INSERT INTO `$table`(" . substr($fields, 1) . ") VALUES\n"; } $data = ""; foreach($row as $item) { $iitem = intval($item); if ($item === NULL) $data .= ",NULL"; else if (strval($iitem) == strval($item)) $data .= ",$item"; else $data .= ",'" . str_replace("'", "''", $item) . "'"; } echo "$eol(" . substr($data, 1) . ")"; $eol = ",\n"; } $res->free(); if ($eol) { echo ";\n"; } echo "\n"; } if (defined('DumpStructureOnly')) { $dumptype = "Wettmeister Database Structure Dump"; echo "-- $dumptype\n\n"; } else { $dumptype = "Wettmeister Database Dump"; echo "-- $dumptype\n"; echo "-- Date: " . strftime("%Y-%m-%d %H:%M:%S") . "\n"; echo "-- Host: " . gethostname() . "\n\n"; echo "-- Site Settings:\n"; echo "-- MatchType='" . MatchType . "'\n"; echo "-- TeamCount=" . TeamCount . " MatchCount=" . MatchCount . " HaveRO16=" . HaveRO16 . "\n"; echo "-- ScoreExact=" . ScoreExact . " ScoreDiff=" . ScoreDiff . " ScoreWin=" . ScoreWin . " ScoreEven=" . ScoreEven . "\n"; echo "-- Bonus0=" . Bonus0 . " Bonus8=" . Bonus8 . " Bonus4=" . Bonus4 . " Bonus2=" . Bonus2 . "\n\n"; } echo "SET character_set_client = utf8mb4;\n\n"; DumpTable('wm_users'); DumpTable('wm_groups'); DumpTable('wm_group_assoc'); DumpTable('wm_teams'); DumpTable('wm_locations'); DumpTable('wm_stations'); DumpTable('wm_matches'); DumpTable('wm_bets'); DumpTable('wm_survey'); DumpTable('wm_log'); echo "-- END of $dumptype\n"; ?>