this code querys a cddb (in thie ex: freedb, via the freedb.pm) and inserts the important info in an sql table. this is the first script im halfway proud of. Im sure there are errors, but it works for me... :]
#!/usr/bin/perl -w use strict; use FreeDB; use DBI; ### DBI shit my $DBhost = "localhost"; my $DBport = "3306"; my $DBdb = "cd"; my $DBtable = "list"; my $DBuser = "cdlist"; my $DBpassword = "cdlist"; my $cd = new FreeDB; $cd->ignore_cache(0); if (!$cd->fetch) { print "couldn't fetch cd info\n"; exit 1; } else { print "Artist => ", $cd->artist, "\n"; print "Title => ", $cd->title, "\n"; while ($cd->next_track) { print "Track number => ", $cd->current_track_number_padded, +". "; print $cd->current_track_info, " ("; print $cd->current_track_time_in_minutes, ")\n"; } insert_cd(); } sub insert_cd { my $dbh = DBI->connect("DBI:mysql:database=$DBdb; host=$DBhost;po +rt=$DBport" , $DBuser , $DBpassword); my $sth = $dbh->do("INSERT INTO $DBtable(discid,artist,title,trac +knum,seconds) VALUES(?,?,?,?,?)", undef, $cd->discid, $cd->artist, $c +d->title, $cd->total_tracks, $cd->disc_length); $dbh->disconnect; system('eject'); return; }

Replies are listed 'Best First'.
RE: cddb to mysql script.
by rdnzl (Sexton) on Jul 31, 2000 at 02:03 UTC
    OOPS i forgot to login before posting that... :]