-1

I'm trying to get this method to work but I'm getting a syntax error output on my console.

method insert($table, \@columns, \@values) {
   return if (!$table && !scalar(@columns) && !scalar(@values));
   my $fields = join(", ", @columns);
   my $statement = $self->{mysql}->prepare("INSERT INTO $table ($fields) VALUES " . join(", ", ("?") x scalar(@columns)));
   $statement->execute(@values);
   return $statement->{mysql_insertid};
}

Any help would be greatly appreciated!

1
  • 1
    Shouldn't VALUES be followed by parentheses? VALUES (?, ?, ...)
    – choroba
    Apr 3, 2015 at 16:11

1 Answer 1

3

VALUES should be followed by parentheses:

VALUES(?, ?, ?)

i.e.

"VALUES (" . join(', ', ('?') x @columns) . ')'
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.