#!/usr/local/bin/perl $| = 1; use DBI; $driver_name = "mysql"; $database = "webtools"; $hostname = "smegma.rasterburn.com"; $datasource = "DBI:$driver_name:$database@$hostname"; my $dbh = DBI->connect("$datasource", $user, $password) || die "Can't connect to $datasource: $DBI::errstr"; if($ARGV[0]) { $sth = $dbh->prepare( q{ SELECT * FROM phonelog WHERE id = ? }) || die "Can't prepare statement: $DBI::errstr"; my $rc = $sth->execute($ARGV[0]) || die "Can't execute statement: $DBI::errstr"; my $rows = $sth->rows; if($rows <= 0) { print "No records found matching ID $ARGV[0].\n"; exit; } print "Query will return $sth->{NUM_OF_FIELDS} fields and $rows rows of data.\n\n"; while(($id, $summary, $catagory, $status) = $sth->fetchrow_array) { # print "$id\t$summary\t$catagory\t$status\n"; write; } } else { $sth = $dbh->prepare( q{ SELECT id, summary, catagory, status FROM phonelog }) || die "Can't prepare statement: $DBI::errstr"; my $rc = $sth->execute() || die "Can't execute statement: $DBI::errstr"; my $rows = $sth->rows; #print "Query will return $sth->{NUM_OF_FIELDS} fields and $rows rows of data.\n\n"; format STDOUT_TOP = Phone Log Log# Summary ------------------------------------------------------------------------------ . format STDOUT = @<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $id, $summary . while(($id, $summary, $catagory, $status) = $sth->fetchrow_array) { # print "$id\t$summary\t$catagory\t$status\n"; write; } #print "\n"; } warn $DBI::errstr if $DBI::err; $sth->finish; my $rc = $dbh->disconnect;