Not sure how well this is supported across various databases, but in my version of MySQL, the result of the execute() call returns the record count:
#!perl -l use strict; use warnings; use Data::Dumper; require 'getdbh.pl'; my $dbh = get_dbh(); $dbh->do('USE test'); $dbh->do('CREATE TEMPORARY TABLE t1 (name char(8))'); for (qw/ Jim Judy Steve Jack Jodie Sally Alice /) { $dbh->do('INSERT INTO t1 VALUES (?)', undef, $_); } for (qw/ J S A X /) { my $sth = $dbh->prepare("SELECT name FROM t1 where name like '$_%' +"); my $x = $sth->execute(); print "$_: \$x = $x"; } __END__ J: $x = 4 S: $x = 2 A: $x = 1 X: $x = 0E0
Update: I'm not sure why this keeps getting downvoted. I know the documentation in DBI says that execute() is only guaranteed to return a true value on success, but a little poking around in DBD::mysql makes me think this is a real feature, if a poorly documented one. I'd be grateful if someone would take the time to explain the --'s.

In reply to Re: Count Number of rows retrieved from SELECT by trammell
in thread Count Number of rows retrieved from SELECT by dtharby

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.