【问题标题】:Perl DBD error FUNCTION dbName.GLOB does not existPerl DBD 错误 FUNCTION dbName.GLOB 不存在
【发布时间】:2012-12-18 09:58:26
【问题描述】:

我开始为一些 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;

提前感谢您的帮助。

【问题讨论】:

  • $id = $UserIDList 不会“从临时文件中读取用户 ID”。它只是将$UserIDList(一个文件句柄)分配给$id。此外,您在顶部缺少use warnings; use strict;,并且您有SQL 注入问题。使用参数化查询!

标签: mysql perl dbd


【解决方案1】:
while ($id = $UserIDList) {

应该是

while ($id = <$UserIDList>) {
    chomp;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-23
    • 2011-10-14
    • 2019-02-09
    • 2014-11-09
    • 2015-07-09
    • 2014-08-17
    • 1970-01-01
    相关资源
    最近更新 更多