in reply to Re: Inserting Multiple Records in DB.
in thread Inserting Multiple Records in DB.

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.

This isn't true at all. In standard-SQL, you can insert multiple rows of data with a single INSERT statement, and if you look at what the "joins" are doing in the OP's code, you'll see that that's what he's doing.

Your other advice sounds about right, though. Using bind parameters (question marks) with prepare is a good habit to get into to guard against SQL-injection attacks.

  • Comment on Re^2: Inserting Multiple Records in DB.

Replies are listed 'Best First'.
Re^3: Inserting Multiple Records in DB.
by Narveson (Chaplain) on Mar 02, 2008 at 02:09 UTC
    In standard-SQL, you can insert multiple rows of data with a single INSERT statement.

    Thank you! This was news to me. I've done my due-diligence Googling now, and I see it's true.

    But when I look at the OP's code, I can't see any syntactic markers for multiple records. The multirow INSERT ... VALUES statement looks like

    INSERT INTO phone_book VALUES ('John Doe', '555-1212'), ('Peter Doe', +'555-2323');

    with a pair of parentheses for each record to be inserted.

    Thanks also to pc88mxer below for the diligent analysis of the parsing routine, confirming that there should be multiple target tables.