Mysql 无法执行SQL查询

Mysql 无法执行SQL查询,mysql,perl,Mysql,Perl,我在一个*.txt文件中有一堆doi,它们之间用'\n'分隔。我编写的perl脚本应该读取文件的每一行并执行select查询。但是,程序无法执行SQL查询。你能帮我解决这个问题吗 执行后,我得到以下错误: 您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 近的 “3.0” dois.txt文件的第一行包含以下DOI: `http://dx.doi.org/10.1002/1521-3757(20001103)112:21<3947::aid-ange394

我在一个*.txt文件中有一堆doi,它们之间用
'\n'
分隔。我编写的perl脚本应该读取文件的每一行并执行select查询。但是,程序无法执行SQL查询。你能帮我解决这个问题吗

执行后,我得到以下错误:

您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 近的 “3.0”

dois.txt文件的第一行包含以下DOI:

`http://dx.doi.org/10.1002/1521-3757(20001103)112:21<3947::aid-ange3947>3.0.co;2-k`
`http://dx.doi.org/10.1002/1521-3757(20001103)112:213.0.co;2-k`
这是我的密码:

my $file = 'dois.txt';

open(my $fh, '<:encoding(UTF-8)', $file)
   or die " Could not open file $file";
while (my $doi = <$fh>) {

chomp($doi);
my $sth = $dbh->prepare("select * from mytable where doi = ''$doi'';");
$sth->execute || die "failed to execute:\n ", $DBI::Errstr;
print $sth->fetchrow_array, "\n";

}
close FH;
$dbh->disconnect;
my$file='dois.txt';

打开(my$fh,您想在循环外调用
prepare
,这样执行计划只需计算一次(即更快)。此外,除了只准备一次查询外,如果使用

my$file='dois.txt';

打开(my$fh,'创建一个字符串并从
发布它“从mytable中选择*,其中doi=''$doi'';”
my $file = 'dois.txt';

open(my $fh, '<:encoding(UTF-8)', $file) or die "Could not open file $file: $!\n";
my $sth = $dbh->prepare(q{select * from mytable where doi = ?});

while (my $doi = <$fh>) {
    chomp($doi);    
    $sth->execute($doi) || die "failed to execute:\n ", $DBI::Errstr;
    print $sth->fetchrow_array, "\n";
}

close $fh;
$dbh->disconnect;