[freetds] exporting data from ODBC to mysql

ZIGLIO Frediano Frediano.Ziglio at mail.vodafone.it
Wed May 21 08:46:38 EDT 2003



> -----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(',', at hdr).') VALUES(';
	# scan all rows
	while (@row = $sth->fetchrow_array()) 
	{
		echo $sql0.join(',', map { s/'/''/g; "'$_'" } @row).")\n";
	}
}
$sth = undef;

freddy77



More information about the FreeTDS mailing list