I had to do some review of this because it can get confusing.

By design you can't get number of rows out of a SELECT statement. You can only get a numerical result out of DELETE or UPDATE statements. The question is how to get that info from Perl DBI? There are 2 ways:

First with a do statement:
 my $rows = $dbh->do("DELETE FROM table_name WHERE col2='X'");
$rows can be a) Integer>0 b) 0E0 c) undef
0E0 is the DB's "true but numeric zero result".
undef would mean the statement failed.

Second with prepare/execute:

my $sth= $dbh->prepare("DELETE FROM table_name WHERE col2=?"); $sth->execute("X"); my $rows = $sth->rows();
$rows can be (like first example): a) Integer>0 b) 0E0 c) undef

I almost always run with RaiseError=1 so checking for undef doesn't come up.

I don't know if DBI returns 1 or 0E0 for a successful SELECT operation.


In reply to Re^7: Can I get the actual error for DBI->execute() ? by Marshall
in thread Can I get the actual error for DBI->execute() ? by SergioQ

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.