I have a bunch of DOIs separated by '\n' in a *.txt file. The perl script I have written should read each line of the file and execute a select query. However, the program is unable to execute the SQL query. Could you please help me fix the problem?
After execution I get the following error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'http://dx.doi.org/10.1002/1521-3757(20001103)112:21<3947::aid-ange3947>3.0'
The first line of the dois.txt file contains the following DOI:
`http://dx.doi.org/10.1002/1521-3757(20001103)112:21<3947::aid-ange3947>3.0.co;2-k`
Here's my code:
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;
"select * from mytable where doi = ''$doi'';"