【发布时间】:2022-11-10 04:58:09
【问题描述】:
我有一个使用 Perl 将数据插入数据库的脚本,如下所示:
$SQL = "INSERT into database (title,time,etc) VALUES ('$title','$time','$etc')";
eval {
$sth = $dbh->prepare($SQL);
};
# check for errors
if($@){
$dbh->disconnect;
print "Content-type: text/html\n\n";
print "An ERROR occurred! $@\n";
exit;
} else {
$sth->execute;
} # end of if/else
return ($sth);
}
尽管转义了违规字符,但有时用户会从 PDF 中复制和粘贴数据,这会导致插入命令失败。如何快速检查以确保插入命令成功,如果不成功,则显示错误?
【问题讨论】:
-
RaiseError 和 PrintError 使用什么值?