I'm trying to parse a few references from a file and load them to mysql table but keep on getting this error everytim,e i run the script:

DBD::mysql::st execute failed: 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 ' Njuguna, M.I., Yusuf, J. A., Akama, V.,2013,Animal husbandry in the developed w' at line 1 at manuscripts3.pl line 51, <$fh> line 1.
Uncaught exception from user code:See code below


use strict;
use warnings;
use diagnostics;
use DBI;

my $driver = "mysql";
my $database = "test";
my $user = "root";
my $password = "";
my $dbh = DBI->connect(
$user, $password,
RaiseError => 1,
PrintError => 1,
AutoCommit => 0,
) or die $DBI::errstr;

my $file = "/var/www/manuscripts.txt";

open my $fh ,"<", $file;
my @manuscripts;
while (my $lines = <$fh>){
    $lines =~ s/\, \(/\t/g;
    $lines =~ s/\) \“/\t/g;
    $lines =~ s/\” /\t/g;

my ($authors, $year, $title, $journal) = split (/\t/, $lines);

What i'm i doing wrong?

Recommended Answers

All 5 Replies

this is the textfile

Kamau, M.A., Njuguna, M.I., Yusuf, J. A., Akama, V., (2013) “Animal husbandry in the developed world” Journal of Hospital Infenction
Kamau, M.A., Njuguna, M.I., Yusuf, J. A., Akama, V., (2013) “Agriculture and global warming” PLOS Medicine
Kamau, M.A., Njuguna, M.I., Yusuf, J. A., Akama, V., (2013) “Rotational farming as a business” The Journal of Infectious Diseases

Try debugging or outputting the sql statement then it will be easier to disgnose.

How do i output/debug the sql statement? i'm at my wits end

This is the missing bit on the code snippet above

my ($authors, $year, $title, $journal) = split (/\t/, $lines);

    push @manuscripts, {
    authors => $authors,
    year => $year,
    title => $title,
    journal => $journal


#print "$title\n";
my $sql = "insert into manuscript($authors,$year,$title,$journal) 
values (?,?,?,?)";
my $stmt = $dbh->prepare($sql);

# disconnect from the MySQL database

Just send it to the browser as htm rather than executing it, or debug it if your ide supports debugguing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.