This is an example of an unusual syntax error for no obvious reasons. The DBI keep returning error string as a syntax error in the last element of the query string 'limit ?'.
1) The calling CGI code:
...
myFunc(param('itemCounts'));
...
2) The Perl library function:
sub myFunc {
my $limit = shift @_;
my $dbh = connectMyDB();
my $sth = $dbh->prepare('SELECT * from myProducts order by itemID DESC limit ?') or return die 'Unable to set handle.';
$sth->execute($limit) or print $sth->errstr;
...
}
---------------------------
This will ALWAYS cause a syntax error when $sth->execute() is called.
---------------------------
3) The Fix:
Modify to have $sth->execute(int($limit)) . The SELECT query was expecting type integer and param('itemCounts') in the CGI context returned as strings/text value.