in reply to Binding values to table with autoincrement ID

Hi,

you have to specify what columns of the table you want to insert values into. So you have to do something like:

my $sql = "INSERT INTO table (col2, col3, col4, col5, col6, col7, col8 +) VALUES (?,?,?,?,?,?,?)";

where colX are the names of the columns to insert into. I assumed that the first column is the autoincrement column. You have to take the real column names.

Without specifying the column names I would guess that the driver is going from left to right in the column definition of the table trying to bind the first variable to the autoincrement column.

My advice: Do always specify the column names. It's more robust against some kind of table layout changes.

McA

Replies are listed 'Best First'.
Re^2: Binding values to table with autoincrement ID
by sowais (Sexton) on Aug 27, 2014 at 18:25 UTC
    Thanks McA! that did the trick!

      Also, you should realise last_insert_id will not work with DBD::ODBC - read last_insert_id