it appears you're doing some kind of backup. I usually do this one of two ways.
small database solution
create a multidimension array and store the table's info into it like so:
<?
//connect to db 1
$sql = "SELECT * FROM table";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result) {
array_push($table,$row);
} //end while
//disconnect from db1
//connect to db2
//loop to insert data from $table into the database
?>
large database solution:
use two scripts
script1 - dumps the data into csv files
script2 - pulls the text files into the other database
then run these with a time off set large enough that they don't conflict in running.