This is a Perl basics question, and I might answer it a bit differently from
others.

Assuming you did this earlier:
    $obj->{dbh} = DBI->connect( ... );
Then $obj->{dbh} is now the reference (handle) representing your DBI
connection.  You can then say:
    foo( $obj->{dbh} );
And then
    sub foo
    {
        my ( $dbh ) = @_;
        $dbh->selectall_arrayref( .... ); # for instance
        ...
    }
uses the handle.  One might question why you assigned into $obj->{dbh}
instead of assigning directly to a variable, as in
    my $dbh = connect( ... );
but that is another matter.

-Will


-----Original Message-----
From: Alec Brecher [mailto:[EMAIL PROTECTED] 
Sent: Monday 10 January 2005 10:35
To: Dbi-Users
Subject: passing dbh


I am trying to figure out the most efficient method of passing around a live
dbh when calling a subs.

I have embedded a dbh into an object: $obj->{dbh} and would like to pass to
it to other functions for reuse.

Should I call: foo( $obj->{dbh} );
or: foo( \$obj->{dbh} );
or something else?

Does the first method copy the dbh and create a new connection?

Thank you.  -Alec

Alec Brecher
E Research Resources
office 802 253-8908


     - - - - - - -  Appended by Scientific-Atlanta, Inc.  - - - - - - -  
This e-mail and any attachments may contain information which is confidential, 
proprietary, privileged or otherwise protected by law. The information is 
solely intended for the named addressee (or a person responsible for delivering 
it to the addressee). If you are not the intended recipient of this message, 
you are not authorized to read, print, retain, copy or disseminate this message 
or any part of it. If you have received this e-mail in error, please notify the 
sender immediately by return e-mail and delete it from your computer.

Reply via email to