Depending on the number of rows, fetching them all can by quite memory consuming. My code (although for DBD::Pg) usually looks like this:

use DBI; use Carp; use English; ... my $dbh = DBI->connect($self->{dburl}, $self->{dbuser}, $self->{dbpass +word}, { AutoCommit => 0, # This is a proper + database, not a key-value store RaiseError => 0, # Child protection + mode off. We are doing our own error checking, thank you very much AutoInactiveDestroy => 1, # Just do + the right thing when using fork() }) or croak("$EVAL_ERROR"); ... # sub bla($dbh) { my $selsth = $dbh->prepare_cached("SELECT foo, bar, baz FROM bli WHERE + bla = ? ORDER BY blub") or croak($dbh->errstr); # If the statement is wrong, no point +of internal error handling if(!$selsth->execute("foobar")) { $reph->debuglog($dbh->errstr); $dbh->rollback; return 0; # Tell caller we failed } # Work on the data row-by-row while((my $line = $selsth->fetchrow_array)) { ... # Do something with the data ... } $selsth->finish; # Make sure we don't leave database pointers and stuf +f around $dbh->commit; # Finish the current transaction, unlock all locked tabl +es/rows and stuff. # commit() may or may not happen in THIS function, depen +ding on if the caller needs to # chain multiple functions in a single transaction return 1; # tell caller we succeeded. ...

PerlMonks XP is useless? Not anymore: XPD - Do more with your PerlMonks XP
Also check out my sisters artwork and my weekly webcomics

In reply to Re^4: DBD::mysql::st fetchrow_hashref failed: fetch() without execute() at (Updates:2) by cavac
in thread DBD::mysql::st fetchrow_hashref failed: fetch() without execute() at by Digioso

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.