in reply to Inserting Multiple Records in DB.
$sql = "INSERT into $table ($fields) values ($values)";
An INSERT ... VALUES statement inserts only one record per execution. You're collecting your data from a structured file using nested loops, so I doubt that it can be modeled very well with a single database record.
For efficiency you can prepare an INSERT statement once, using question marks as placeholders for the individual values, then loop through all the records. On each pass through the loop, bind a new set of values to the placeholders, then call execute() on the statement handle.
In fact you need multiple INSERT statements, one for each destination table.
You may wish to prepare all your INSERT statements before you begin reading the data, then call bind and execute at all the places you have marked with # push
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Inserting Multiple Records in DB.
by doom (Deacon) on Feb 29, 2008 at 22:34 UTC | |
by Narveson (Chaplain) on Mar 02, 2008 at 02:09 UTC | |
|
Re^2: Inserting Multiple Records in DB.
by Anonymous Monk on Feb 29, 2008 at 22:30 UTC | |
by doom (Deacon) on Feb 29, 2008 at 22:36 UTC | |
|
Re^2: Inserting Multiple Records in DB.
by Anonymous Monk on Feb 29, 2008 at 22:50 UTC |