in reply to Inserting to MySQL 4.1 database using Perl DBI

There are two errors in your code.

First, your SQL statement is not syntactically correct, because you have the word GO at its end:

my $insert= $dbh->prepare("INSERT INTO $table ($columns) VALUES ($rows +)GO");

Second, you are not properly quoting your values. Strings must be passed in (most) SQL databases surrounded by single quotes, while numbers are not allowed to have single quotes.

You should really be using placeholders so you don't need to guess as to what has to be quoted and what not and what the correct quoting characters are:

# Construct a string of "?" as the placeholders: my $placeholders = join ",", map { "?" } keys %{$mirror{"$Itemnumber"} +{"$table"}}; my $insert= $dbh->prepare("INSERT INTO $table ($columns) VALUES ($plac +eholders)"); $insert->execute(values %{$mirror{"$Itemnumber"}{"$table"}});

Replies are listed 'Best First'.
Re^2: Inserting to MySQL 4.1 database using Perl DBI
by Mr.Churka (Sexton) on Jan 07, 2008 at 14:51 UTC
    That worked perfectly.