1

I am starting to write some Perl scripts for some cron jobs that will query the database and send out reminders about upcoming events. I'm quite new to database access in Perl as most of my work thus far has been on the web end using PHP. Anyway, the first query is working fine to generate a temporary output file and then I'm reading back in that output file to loop thru the results querying to find the specific events for the users discovered in the first query.

The problem that I am running into now is getting the following error:

./remind.pl 
DBD::mysql::st execute failed: FUNCTION dbName.GLOB does not exist at ./remind.pl line 41.
SQL Error: FUNCTION dbName.GLOB does not exist

This is my Perl code

$host = 'localhost';
$database = 'dbName';
$user = 'user';
$password = 'password';

use POSIX qw(strftime);
use List::MoreUtils qw(uniq);
use Mail::Sendmail;
use DBI;

$dt = strftime("%Y%m%d%H%M%S", localtime(time));
$List30 = "../tmp/queries/30DayUserList.$dt";
open my $UserList30Day, ">> $List30" or die "Can't create tmp file: $!";

$dbh = DBI->connect('dbi:mysql:dbName',$user,$password) or die "Connection error: $DBI::errstr\n";

$sql = "SELECT DISTINCT user FROM shows WHERE initial_date BETWEEN CURDATE() AND CURDATE() + INTERVAL 30 DAY";
$sth = $dbh->prepare($sql);
$sth->execute or die "SQL Error: $DBI::errstr\n";

while (@jeweler = $sth->fetchrow_array()) {
print $UserList30Day "$user[0]\n";
}
close $UserList30Day;

open my $UserIDList, "< $List30" or die "Can't open temp file: $List30";

while ($id = $UserIDList) { # Read in User ID from temp file as $id
# Query for show information for next 30 days

my $sql = "SELECT shows.initial_date, shows.initial_time, shows.hostess_key, hostess.hostess_fname, hostess.hostess_lname, hostess.primary_phone, hostess.address1, hostess.address2, hostess.city, hostess.zipcode, hostess.state
        FROM shows, hostess
        WHERE shows.user = $id
        AND initial_date BETWEEN CURDATE() AND CURDATE() + INTERVAL 30 DAY
        AND shows.hostess_key = hostess.hostess_key";
my $sth = $dbh->prepare($sql);
$sth->execute or die "SQL Error: $DBI::errstr\n";

# Iterate thru query results to create output data
while (@row = $sth->fetchrow_array()) {
    $content = "Reminder: You have a show for $row[3] $row[4] coming up on $row[0] at $row[1].\n";
    $content .= "Location:  $row[6] \n";
    if ($row[7] != '') {
        $content .=  "           " . $row[7] . "\n";
    }
    $content .=  "           $row[8], $row[10]  $row[9] \n";
    $content .=  "Phone: $row[5] \n";
}

%mail = (To => 'email',
    From => 'email',
    Subject => 'Just another test',
    Message => $content
    );

# sendmail(%mail) or die $Mail::Sendmail::error;
print %mail;
}
close $UserList30Day;

Thanks in advance for any assistance.

Borodin
  • 126,100
  • 9
  • 70
  • 144
Scott Nipp
  • 121
  • 12
  • 4
    `$id = $UserIDList` does not "Read in User ID from temp file". It simply assigns `$UserIDList` (a filehandle) to `$id`. Also, you're missing `use warnings; use strict;` at the top, and you have SQL injection problems. Use parameterized queries! – melpomene Jan 03 '13 at 23:47

1 Answers1

3
while ($id = $UserIDList) {

should be

while ($id = <$UserIDList>) {
    chomp;
ikegami
  • 367,544
  • 15
  • 269
  • 518