Hi!

I'm writing a simple script to output data from a MySQL database...
Eventually I'd like to pipe it all into a .tex file and make a custom pdf
out of it.

However, I'm running into a problem: the FIRST instance of
DateTime::Format::MySQL works perfectly... but when I get to the second
one, it throws me this error:

Use of uninitialized value $input in concatenation (.) or string at
/usr/local/share/perl/5.14.2/
DateTime/Format/Builder.pm line 154.
Invalid date format:  at ./logbook.pl line 29

Here's my code:

#! /usr/bin/perl

#use strict;
use DBI;
use DateTime::Format::MySQL;


my $dbh = DBI->connect(
    "dbi:mysql:dbname=dbname",
    "user",
    "password",
    { RaiseError => 1 },
) or die $DBI::errstr;

my $sth = $dbh->prepare("select l.id, l.date_added, l.username,
                        l.entry, c.comment_date_added, c.username as cuser,
                        c.comment from logbook as l
                        left join comments as c on l.id = c.logbook_id
                        order by l.date_added desc");
$sth->execute();


my $row;
while ($row = $sth->fetchrow_hashref()) {
my      $id = $row->{id};
my      $date_added =
DateTime::Format::MySQL->parse_timestamp($row->{date_added});
my      $username = $row->{username};
my      $entry = $row->{entry};
my      $comment_date =
DateTime::Format::MySQL->parse_timestamp($row->{comment_date_added});
my      $comment_username = $row->{cuser};
my      $comment = $row->{comment};

        print "Entry Id: $id, Entry Date: " . $date_added->strftime("%a, %d
%b %Y at %l:%M %p") . "\nUsername: $username\n\n\t$entry\n\n";
        if($row->{comment} ne '') {
                print "\t\tDate: " . $comment_date->strftime("%a, %d %b %Y
at %l:%M %p") . "\n";
                print "\t\tUsername: $username\n";
                print "\t\t\t $comment\n\n";
        }
}


$sth->finish();
$dbh->disconnect();


Can anyone give me a tip? I've no idea what I'm doing wrong here... if I
run this without the 2nd timestamp format it works great, I'd just like the
readability.

Reply via email to