in reply to Re: Re: foreach within a foreach
in thread foreach within a foreach

Placeholders make sure that the data is quoted correctly. Remember, when inserting strings into your database, they must be surrounded by quotes, yet numbers cannot be. This strict either/or but not both situation means that you need to decide in advance how to quote. If you put quotes in your statement, but change data types later, you are going to break that part of your program in some way that isn't visible until that statement is run.

The other thing you can do is let DBI do it for you, which is what placeholders do. DBI keeps track of how each column has to be treated, and quotes accordingly. As an additional bonus, some driver implementations, such as DBD::mysql can actually save these generic statements and recycle them later. In shotgunefx's example, the execute could be called many times on exactly the same prepared statement.

Replies are listed 'Best First'.
Re: Re^3: foreach within a foreach
by Silicon Cactus (Scribe) on Jun 10, 2002 at 14:40 UTC
    Changing my scripts now. <grin>

    Thanks for the complete answers everyone, and the link- you helped me learn quite a bit, and save a bit of time, too.
    ++ to all. :)