First, look in the DBD::mysql docs and use mysql_insertid instead of doing another select to get the last id inserted.

Second, you should be using the DBI quote method or placeholders (my preference is placeholders), instead of pasting your variables directly into the sql statement. Placeholders would save you from all that backwhacking of quotes, and in some databases you'd use single instead of double quotes to quote the args, so if you ever migrated, it'd save one extra headache. Placeholders don't get you alot efficiency-wise in mysql, its true, but in combination with prepare_cached can save a bit in statement handle creation (of course then the dbh would have to be persistent also using connect_cached or a package global or as an object attribute or something...).

Third, I think its kind of pointless to copy all those parameters to local args, just to paste them into the sql statement. I'd do something like the insert_hash example in the DBI docs. If this InsertProspect method is already in your main Prospect (or whatever you're calling it) class/package, then I'd not use the accessor methods and just use a hash slice (assuming your object IS a hash underneath) to get all the names and values for the insert statement.


In reply to Re: MySQL / DBI / OOP by runrig
in thread MySQL / DBI / OOP by rogueFalcon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.