那是我的代码的一部分。我使用从 gmail 收到的消息 ID 进行选择。 msg_id以base64形式存储在数据库中,不带符号“< >”。
my $inbox = $imap->select("Inbox") or die "Select error: ", $imap->LastError, "\n";
my @mails = ( $imap->unseen );
foreach my $msgid (@mails) {
my $m_id = $imap->parse_headers( $msgid, "Message-id" )->{"Message-id"}->[0] . "\n";
$m_id =~ s/[<\>]//g;
$m_id = encode_base64($m_id);
$m_id =~ s/\r?$//;
my $q1 = "select id from mails.mails_in where user_id=$param[5] and message_id=$m_id and user_remote_id=$param[6]";
$sth = $dbh->prepare($q1);
$rv = $sth->execute();
my @array;
while ( @array = $sth->fetchrow_array() ) {
foreach my $i (@array) {
print "$i\t";
}
print "\n";
}
}
但是出现这个错误。
DBD::Pg::st execute failed: ERROR: column "zdjkot..." does not exist
LINE 1: ...mails.mails_in where user_id=15206 and message_id=ZDJkOTQ1NT...
^ at ./script.pl line 65.
我尝试从基础开始使用现有的 msg_id - 结果是相似的。 另一个 SELECT 的工作正常。 类似的 SELECT 在 php 上可以正常工作。
我使用: Perl v5.18.2、PostgreSQL v8.4.14
最佳答案
$m_id
缺少单引号
my $q1 = "select id from mails.mails_in where user_id=$param[5] and message_id='$m_id' and user_remote_id=$param[6]";
但使用 ?
占位符总是更好,
my $q1 = "select id from mails.mails_in where user_id =? and message_id =? and user_remote_id =?";
$sth = $dbh->prepare($q1);
$rv = $sth->execute($param[5], $m_id, $param[6]);
因为您不必担心引号、参数转义或 SQL injection attacks .
关于perl - DBD::Pg::st 执行失败:错误:列 "***"不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25863770/