MySQL Forums
Forum List  »  Other Migration

Re: Conversion between FoxPro .DBF and MySql Database
Posted by: Josh Chamas
Date: September 26, 2004 09:51AM


If FoxPro has an ODBC interface to it, a program could be written that takes the data from the ODBC interface to it, and push the data into MySQL that way. Such a program if written in Perl as an example might look like this:

#!/usr/bin/perl

# ( see http://www.activestate.com for free Perl for windows )
#
# This sample code comes with no warranties, nor is guaranteed to even do anything useful
# nor even work, its just a method example for doing a quick data transfer.

use DBI;
use DBD::ODBC;
use DBD::mysql;

my $mssql_dbh = DBI->connect('dbi:ODBC:DSN_NAME', $user, $pass,
{ RaiseError => 1 });
my $mysql_dbh = DBI->connect('dbi:mysql:host=HOST_NAME;database=DB_NAME', $user, $pass,
{ RaiseError => 1 });

my $export_sth = $mssql_dbh->prepare("select col1, col2 from TABLE_NAME");
$export_sth->execute;
while(my $row = $export_sth->fetchrow_array) {
my($col1, $col2) = @$row;
$mysql_dbh->do("insert into TABLE_NAME (col1, col2) values (?,?)", undef, $col1, $col2);
}

$export_sth->finish;
$mysql_dbh->disconnect;
$mysql_dbh->disconnect;





Josh Chamas
Director, Professional Services
MySQL Inc., www.mysql.com
Get More with MySQL! http://www.mysql.com/consulting

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: Conversion between FoxPro .DBF and MySql Database
18538
September 26, 2004 09:51AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.