1

我开始为一些 cron 作业编写一些 Perl 脚本,这些作业将查询数据库并发送有关即将发生的事件的提醒。我对 Perl 中的数据库访问非常陌生,因为到目前为止我的大部分工作都是使用 PHP 在 Web 端进行的。无论如何,第一个查询可以很好地生成一个临时输出文件,然后我正在读取该输出文件以循环通过结果查询来查找在第一个查询中发现的用户的特定事件。

我现在遇到的问题是出现以下错误:

./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

这是我的 Perl 代码

$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;

提前感谢您的任何帮助。

4

1 回答 1

3
while ($id = $UserIDList) {

应该

while ($id = <$UserIDList>) {
    chomp;
于 2013-01-04T00:13:04.047 回答