
Kanji
User
/ Moderator
Jan 27, 2001, 3:39 PM
Post #2 of 2
(6268 views)
|
This is trivial to do using DBI.pm, DBD::CSV and DBD::mysql to read from one and insert into the other. Something like ...
$read = $csv->prepare("SELECT id,name FROM table"); $write = $mysql->prepare("INSERT INTO table ( no,name ) VALUES ( ?,? )"); # now loop over each ... while ( my $row = $read->fetchrow_arrayref ) { $write->execute( @$row ); } ... where $csv and $mysql are DBI handles to the respective databases. Remapping fields is then as simple as making sure whatever you SELECT has the same order as what you INSERT (ie, the above inserts data from the 'id' column into 'no'). Alternately, if your CSV is very simple, there's an example in the DBI docs themselves of reading from CSV and inserting into a db.
|