From the DBI pod:

       "fetchall_hashref" NEW
             $hash_ref = $dbh->fetchall_hashref($key_field);

           The "fetchall_hashref" method can be used to
           fetch all the data to be returned from a pre­
           pared and executed statement handle. It returns
           a reference to a hash that contains, at most,
           one entry per row.

           If there are no rows to return,
           "fetchall_hashref" returns a reference to an
           empty hash. If an error occurs,
           "fetchall_hashref" returns the data fetched
           thus far, which may be none.  You should check
           "$sth-">"err" afterwards (or use the "RaiseEr­
           ror" attribute) to discover if the data is com­
           plete or was truncated due to an error.

           The $key_field parameter provides the name of
           the field that holds the value to be used for
           the key for the returned hash.  For example:

             $dbh->{FetchHashKeyName} = 'NAME_lc';
             $sth = $dbh->prepare("SELECT FOO, BAR, ID,
                              NAME, BAZ FROM TABLE");
             $hash_ref = $sth->fetchall_hashref('id');
      
           The $key_field parameter can also be specified
           as an integer column number (counting from 1).
           If $key_field doesn't match any column in the
           statement, as a name first then as a number,
           then an error is returned.

           This method is normally used only where the key
           field value for each row is unique.  If multi­
           ple rows are returned with the same value for
           the key field then later rows overwrite earlier
           ones.


           The $key_field parameter can also be specified
           as an integer column number (counting from 1).
           If $key_field doesn't match any column in the
           statement, as a name first then as a number,
           then an error is returned.

           This method is normally used only where the key
           field value for each row is unique.  If multi­
           ple rows are returned with the same value for
           the key field then later rows overwrite earlier
           ones.

       print "Name for id 42 is $hash_ref->{42}->{name}\n";

           The $key_field parameter can also be specified
           as an integer column number (counting from 1).
           If $key_field doesn't match any column in the
           statement, as a name first then as a number,
           then an error is returned.

           This method is normally used only where the key
           field value for each row is unique.  If multi­
           ple rows are returned with the same value for
           the key field then later rows overwrite earlier
           ones.

You need a unique key from the data to index the hash.

After Compline,
Zaxo


In reply to Re: DBI error by Zaxo
in thread DBI error by hakkr

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.