George, that's probably about the easiest way you could do it in perl.
If you want every column transferred you could do a "SELECT *" instead
of enumerating columns I think.

Dan


On 9/29/06, George Law <[EMAIL PROTECTED]> wrote:
Hi All,

I have 2 separate mysql servers and need to import data from a table on
sever1 to
a table on server2.  This would need to be done in Perl.

The script in question already has open handles to both servers, so I
know I can
select all the rows from server1 and process them one by one and insert
into the table on server2, but I was wondering if there was a more
simple way to do this which would allow me to transfer the data from one
database handle directly to another?

Looking on google, the closest example I can find is something like :

#!/usr/bin/perl
use DBI;

$dbh1=.....;
$dbh2=.....;
...

$statement = "select a,b,c,d,... from table1 where condition='$value'";
$sth=$dbh1->prepare($sql);
my @results;
while (@results = $sth->fetchrow_array) {

  # build placeholders based on num of fields
  my $placeholders;
  $placeholders .= ($placeholders ? ",?" : "?") for (@results);

  my $sth2 = $dbh2->prepare("INSERT INTO table2 values
($placeholders);");
  $sth2->execute(@results);
  $sth2->finish;
}

$sth1->finish;
$dbh1->disconnect();
$dbh2->disconnect();




George Law
[EMAIL PROTECTED]
MSN: [EMAIL PROTECTED]
Phone: 864-678-3161


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to