kiat, the main advantage of
prepare over
do is most apparent when executing multiple queries. Quoting from the DBI doc:
The do() method can be used for non repeated non-SELECT statement (or with drivers that don't support placeholders).
I have used both, but find
prepare more versatile, especially when using placeholders. And because I want to be as consistent as possible in my coding style, I just stick to
prepare for DBI queries. I'll be curious to see how other more XP'd monks reply--always educational.
Check out Paul Dubois's book
MySQL and Perl for the Web as he does discuss this topic a bit (I'd quote it, but it's at the office).
Update:
Okay, I stopped by the office, and with apologies to Dubois and New Riders, here's the take on
do vs
prepare:
you do have to use the
undef as an argument when using placeholders (see
jeffa's node above)
prepare, because of it's reusable query plan, works best when inserting data into a table via a loop
also because of it's reusable query,
prepare can give a performance boost
use of
prepare makes transporting code to other databases easier and more efficient.
But buy the book for all the details--it's invaluable--the title tells it all.
—Brad
"A little yeast leavens the whole dough."
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.