iang has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have a question regarding a part of the documentation (under CPAN) for Class::dbi under the section Quick Retrieval. The Line: return map $class->construct($_), $sth->fetchall_hash;. I don't understand the "$sth"? Do I need to use a DBI call along with the prepare, execute and fetch? I have searched for any documentation, but I cannot seem to find anything relevant. Any help or pointers? Thanks

Replies are listed 'Best First'.
Re: Class::DBI construct
by ikegami (Patriarch) on Aug 19, 2009 at 20:18 UTC

    Do I need to use a DBI call along with the prepare, execute and fetch?

    No, you don't have to.

    For starters, you don't have to use construct. There are plenty of other means for creating and loading objects.

    If you do use construct, it simply allows you to construct an object from a hash or multiple objects from an array of hashes. This includes the AoH returned by $sth->fetchall_hash, but it's not limited to that source. It doesn't need to come from a database at all.