in reply to DBI returning error on selectrow_hashref

Prior to executing your second example, somehow your database handle $dbh has become undefined (that's what the error messgae means). Are you disconnecting or something before that?

Replies are listed 'Best First'.
Re^2: DBI returning error on selectrow_hashref
by wazzuteke (Hermit) on Nov 28, 2005 at 17:11 UTC
    I think your first comment is the culperate. You should only get this error if your $dbh variable is not defined in-line within the application.

    If the handle is disconnected, the variable should still be defined. Although will recieve another DBI specific error such as "DBI: Cannot selectrow_hashref from a disconnected database handle" (I really don't know the specific error off hand), you should not expect to see the Perl error.

    However, for future reference, and a little off-topic, if you think there might be a chance you are running into an area where your database handle might be disconnected, you can always test against the boolean handle attribute 'Active' and reconnect. For example:
    unless ( $dbh->{'Active'} ) { # Some re-connection magic here }
    Good Luck!!

    ---hA||ta----
    print map{$_.' '}grep{/\w+/}@{[reverse(qw{Perl Code})]} or die while ( 'trying' );
      Your example is good for some uses, but won't prevent the kind of error the OP shows, in fact it will generate a second error of the same kind. A disconnected $dbh is still a $dbh object, his error showed there was no $dbh so doing $dbh->{Active} would generate the same error.