Skip to Content.
Sympa Menu

freetds - RE: [freetds] exporting data from ODBC to mysql

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "ZIGLIO Frediano" <Frediano.Ziglio AT mail.vodafone.it>
  • To: "FreeTDS Development Group" <freetds AT lists.ibiblio.org>
  • Subject: RE: [freetds] exporting data from ODBC to mysql
  • Date: Wed, 21 May 2003 14:46:38 +0200



> -----Original Message-----
> From: Scott Antonivich [mailto:scott AT tpk.net]
> Sent: martedì 20 maggio 2003 16.32
> To: freetds AT lists.ibiblio.org
> Subject: [freetds] exporting data from ODBC to mysql
>
>
> Hello,
>
> Please bare with me as this is all new territory for me. Here
> is what I want
> to do:
>
> I installed freetds on a RedHat Linux 8.0 box. I am trying to
> connect and
> export a table from a mssql7 database. Below is the script
> that I am using:
>
> #!/usr/bin/perl
>
> use DBI;
> $ENV{'SYBASE'} = '/usr/';
> $dbh = DBI->connect('dbi:Sybase:server=XXX', 'XXX', 'XXX')
> or die 'connect';
>
> $dbh->do("use XXX");
>
> $sth = $dbh->prepare('select * from XXX') or die 'prepare';
> $sth->execute or die 'execute';
>
> while (@data = $sth->fetchrow_array) {
> print "$data[0] $data[1] $data[2]\n"; # the first few fields
> }
>
> $sth->finish;
> $dbh->disconnect;
>
>
>
>
> My question is how do I modify the above script to get the data from a
> specific table and imput it into a specific myswl database on
> my linux box?
>
> Thank you for the help.
>
>
> Scott
>

I use this code to produce insert commands

$table = 'XXXX';
$sth = $dbh->prepare("SELECT * FROM $table");
if ($sth and $sth->execute())
{
@hdr = @{$sth->{NAME}};
$sql0 = qq|INSERT INTO $table(|.join(',',@hdr).') VALUES(';
# scan all rows
while (@row = $sth->fetchrow_array())
{
echo $sql0.join(',', map { s/'/''/g; "'$_'" } @row).")\n";
}
}
$sth = undef;

freddy77




Archive powered by MHonArc 2.6.24.

Top of Page