in reply to DBD::mysql::st execute failed: You have an error in your SQL syntax;

Though using the 'do' method is less code, using 'prepare' gives you the opportunity to add another 'die' command;

my $sth = $dbh->prepare($query) or die "unable to prepare:$DBI::errstr\n";

This will show if the error is in the SQL or in the execution

Good to see the ? placeholders in use. Our server failed a penetration test as my boss put the variables straight into the SQL statement! :)

I don't think you need the double quotes around the variables provided to the execute method, wont they take care of themselves?

  • Comment on Re: DBD::mysql::st execute failed: You have an error in your SQL syntax;
  • Download Code

Replies are listed 'Best First'.
Re^2: DBD::mysql::st execute failed: You have an error in your SQL syntax;
by perlfan (Parson) on Jun 22, 2016 at 18:15 UTC
    It's a personal preference, but all you need is RaiseError set to 1 (as you have).