DBI->trace() looks like a good place to get some more information about what's going on.

I was puzzled by this:

$count = 0 ; .... while($array = $sth1->fetchrow_array()) { $count++ ; if ($sth1->rows == 0) { print "No records matched for $ref\nn" ; } elsif ($count == 1) { $t = $array ; print "Entering taxID_format with $t\n" ; #&taxID_format($t) ; } }
I find that $array = $sth1->fetchrow_array() fetches the next row, and sets $array to the value of the first field, or undef if no more rows. Leaving aside the possibility that a row may have an undef first column (or '0')... I don't see the purpose of the if ($sth->rows == 0). Further, I note that the documentation (http://search.cpan.org/~timb/DBI-1.607/DBI.pm#rows) says: "Generally, you can only rely on a row count after a non-SELECT execute ..., or after fetching all the rows of a SELECT statement.".

That said, unless the $sth->rows returns 0 (which is not what the documentation suggests), then the problem is elsewhere and some earlier operation is not doing what y'all expected.


In reply to Re: dbi retieve single col value by gone2015
in thread dbi retieve single col value by Anonymous Monk

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.