Greetings all,
This is a smallish issue and not a mission critical one (at least not for me), but I was wondering about the difference in behavior for UPDATE|DELETE|INSERT queries in DBI. Here is the issue. I am running MySQL 4.0 and have noticed over the past few months that return values from DBI calls differ depending on how the query is executed. example:
###idiosyncratic paranoid method wherein I prepare everything. my $sth = $dbh->prepare("UPDATE mytable SET value1=?, value2=? WHERE i +d=?") || die $dbh->errstr; my $update_success = $sth->execute($val1,$val2,$id) || die $sth->errst +r; ###non paranoid method cleaner as well. my $update_success = $dbh->do("UPDATE mytable SET value1='$val1', valu +e2='$val2' WHERE id=$id") || die $dbh->errstr;
The issue arises when checking the value of $update_success. The first method does not return a value consistently (at least not consistently enough for me to code with). Where as the latter method returns a value but does not allow for the flexibility of the first method, and the query must be recreated with each successive call.
So, Is there something I am missing or shouldn't both methods return a value? I have already realized that the update failure returns "0E0" and not just "0" as I had originally thought, but aside from this why does preparing any type of query other than a "SELECT" not return values? Should I be checking some property of the statement handle? the database handle? or am I stuck not preparing non-select queries? Has anyone else come across this behavior as well?
Thank you all in advance.
-injunjoel

In reply to Return values from $dbh->do vs. $sth->execute(); by injunjoel

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.