I wrote the quick, poorly-written, yet functioning code below to interface with a database of appointments. The intent of the script is to send me a notice via email a day before the event occurs. It doesn't seem to mater what I do, I can't make the script send me an email ONLY when the query is true. I'm open to any ideas.
#!/usr/bin/perl use Date::Manip; use DBI; use strict; my $mailprog = '/usr/lib/sendmail'; my $tomorrow=&DateCalc("today","+1day"); my $year = substr $tomorrow, 0, 4; my $month = substr $tomorrow, 4, 2; my $day = substr $tomorrow, 6, 2; my $tomorrow = $year."-".$month."-".$day; my ($dsn) = "DBI:mysql:andrewkmitchell_com:localhost"; # data source n +ame my ($user_name) = "akm2"; # user name my ($password) = "merlin2562"; # password my ($dbh, $sth); # database and statement handles my (@ary); # array for rows returned by query # connect to database $dbh = DBI->connect ($dsn, $user_name, $password, { RaiseError => 1 }) +; # issue query my $query = qq{ SELECT id, name, event_date, start_time, end_time, des +cription FROM ltw_events WHERE event_date="$tomorrow" }; $sth = $dbh->prepare ( $query ); $sth->execute (); open(MAIL,"|$mailprog -t"); print MAIL "To: akm2\@merlin-internet-services.net\n"; print MAIL "From: root\@merlin-Internet-Services.net (Re-minder)\n"; print MAIL "Subject: Reminder for Tomorrow ($tomorrow)\n"; print MAIL "X-Priority: 1 (Highest)\n\n"; print MAIL "This in an automatic message generated by Re-Mind. The pu +rpose of this message is to remind you of event(s) you have scheduled + for tomorrow ($tomorrow).\n\nEvents are listed below:\n\n"; while (@ary = $sth->fetchrow_array ()) { print MAIL join ("\t", @ary), "\n"; } print MAIL "\nEND OF SCHEDULED EVENTS!\n"; close(MAIL); $sth->finish (); $dbh->disconnect (); exit (0);
Andrew Kenton Mitchell
Andrew@AndrewKMitchell.com
In reply to Testing to see if a MySQL query is true by akm2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |