$end) return false; } return true; } // foreach($tables as $n => &$table){ $r = $sql->query('SELECT * FROM `'.$table.'`;'); if(!$r){ fprintf(STDERR, "Failed to SELECT * FROM $table\n"); return 1; } fprintf(STDERR, 'Begin %s ', $table); fflush(STDERR); $outSQL = "BEGIN TRANSACTION;\n"; $n = 0; $rows = 0; $needHead = true; while( ($row = $r->fetch_assoc()) ){ $n++; $rows++; if($n == 300){ $outSQL .= ";\n"; $outSQL .= "COMMIT TRANSACTION;\n"; $outSQL .= "BEGIN TRANSACTION;\n"; fprintf(STDERR, '.'); fflush(STDERR); $needHead = true; $n = 0; } $cols = ''; $data = ''; $i = 0; foreach($row as $name => &$value){ if($i++ > 0){ $cols .= ', '; $data .= ', '; } $cols .= "[$name]"; if(check_int($value)) $data .= "$value"; else $data .= "'".addslashes($value)."'"; } unset($name, $value); if($needHead){ $needHead = false; $outSQL .= "INSERT INTO [$table] ($cols) VALUES "; $outSQL .= "($data)"; }else $outSQL .= ", ($data)"; //$outSQL .= "INSERT INTO [$table] ($cols) VALUES ($data);\n"; unset($cols, $data); } $outSQL .= ";\n"; $outSQL .= "COMMIT TRANSACTION;\n"; $outSQL .= "-- Table $table => $rows Rows\n\n"; fprintf(STDERR, " done (%u Rows)\n", $rows); print $outSQL; unset($r, $outSQL); }