in reply to Array values into a database help!
Three ways to adjust the values:
my $sth = $dbh_in->prepare(" INSERT INTO my_table ( name_1, name_2, name_3, name_4 ) VALUES ( ?,?,?,? ) "); $sth->execute($fields[0], $fields[1], $fields[2], $fields[3]); $sth->execute(@fields[0..3]); $sth->execute((@fields, undef, undef, undef, undef)[0..3]);
One way to adjust the query:
my $sth = $dbh_in->prepare(" INSERT INTO my_table ( " . join(', ', map 'name_'.$_, 1..@fields) ." ) VALUES ( " . join(',', ('?') x @fields) ." ) "); $sth->execute(@fields);
(I'm assuming WHERE user=... shouldn't be there? If it is, be sure to use a placeholder for that too!!!)
Update: Added more ways of adjusting the values.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Array values into a database help!
by Anonymous Monk on Nov 28, 2010 at 05:13 UTC | |
by ikegami (Patriarch) on Nov 28, 2010 at 06:07 UTC | |
|
Re^2: Array values into a database help!
by Anonymous Monk on Nov 29, 2010 at 00:52 UTC | |
by ikegami (Patriarch) on Nov 29, 2010 at 04:00 UTC |