in reply to DBI SQL adding array of values
Ugly, Ugly code.
If still get a "26 values when 25 are expected" error, try usingmy $tstr = '?'; my $tv = join (', ', @table); for (1..$#table) { $tstr.=', ?'; } my $sth = $ebh->prepare("INSERT INTO member_info ($tv) VALUES ($tstr)" +) or die "Unable to prepare statement: ($DBI::err) $DBI::errstr"; if (scalar @data = scalar @table) { $sth->execute(@data) or die "No exec: ($DBI::err) $DBI::errstr"; } else { warn("\@data is not the same size as \@table; tried to put ".scalar + @data." items into ".scalar @table." columns."); }
Update: I forgot to note that the above should only be used as a test, as it will insert a NULL into the first column of your tables. Thanks, jZed, for reminding me.$sth->execute( undef,@data )
execute_array does something different.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: DBI SQL adding array of values
by jZed (Prior) on Oct 27, 2004 at 15:42 UTC | |
by radiantmatrix (Parson) on Oct 27, 2004 at 18:16 UTC | |
|
Re^2: DBI SQL adding array of values
by bart (Canon) on Oct 28, 2004 at 00:17 UTC | |
by radiantmatrix (Parson) on Oct 29, 2004 at 17:09 UTC | |
by diotalevi (Canon) on Oct 29, 2004 at 17:29 UTC | |
by radiantmatrix (Parson) on Oct 29, 2004 at 20:30 UTC |