I want a simple script that lists out artists and their CDs in my database.
#!/usr/bin/perl
use strict;
use DBI();
my $dbh1 = DBI->connect("DBI:mysql:database=cddb;host=localhost","uuuu", "xxxxxx", { raiseError => 1, AutoCommit => 0 })
|| die "Database connection not made: $DBI::errstr";
my $sql = "SELECT artist.name, cd.title FROM artist, cdtable AS cd WHERE artist.id = cd.artid";
my $sth = $dbh1->prepare($sql);
$sth->execute();
my( $name, $title );
$sth->bind_columns( \$name, \$title );
print "Name\t\tTitle\n";
while( $sth->fetch() ) {
print "$name\t$title\n";
}
$dbh1->disconnect() if($dbh1)
D:\Documents and Settings\timj\perl>c:\Perl\bin\perl cd.pl
Name Title
Phatfish Guaranteed
Phatfish 15
Bethany Dillon Waking Up
Bethany Dillon Bethany Dillon
Bethany Dillon Imagination
Nick Drake Made To Love Magic
Nick Drake Five Leaves Left
Nick Drake Bryter Layter
D:\Documents and Settings\timj\perl>
That's about as simple as it get, I'm sure that there is far more to it than that, but this will do for now!
Tim
No comments:
Post a Comment