Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: DBI error

by Zaxo (Archbishop)
on Sep 25, 2002 at 17:00 UTC ( [id://200666]=note: print w/replies, xml ) Need Help??


in reply to DBI error

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://200666]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2025-07-11 12:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.