Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2004
    Posts
    5

    Unanswered: passing a database handle

    Hello:

    if I have a database hande, $dbh:

    $dbh = new Sybase:Blib;

    and I pass $dbh to a sub:

    someSub($dbh);

    where

    someSub {

    ($dbh2) = @_;

    }

    Is $dbh2 a reference to a reference to an object or is it a reference to an object?

    IOW do I access $dbh's methods like $dbh2->dbsqlexec; or something like $$dbh->dbsqlexec? Sorry if this is a stupid question.

    Adam

  2. #2
    Join Date
    Apr 2004
    Posts
    16
    $dbh and $dbh2 are both the same things. They are scalars whose values are references to the same instance of the Sybase::DBlib class.

    A reference is simply a scalar which has a pointer to some memory location as its value. You can treat these scalars just like any other scalar. To dereference them and access their object, though, you use the -> operator.

    That said, you should "use strict" and define the scope of all your variables using "my".
    perl -le 'print reverse reverse "just another perl hacker"'
    wush.net subversion hosting - remote hosted revision control with easy admin, ssl security & backups

  3. #3
    Join Date
    Jul 2005
    Location
    UK, England
    Posts
    14
    Or for a more complete answer:

    Code:
    $dbh = new Sybase::eek: Blib;
    
    &CloseDBIConnection($dbh);
    
    sub CloseDBIConnection {
    if (defined($_[0])) {
       my $dbh = $_[0];
       $dbh->disconnect || die($dbh::errstr);
       undef $dbh;
       undef $_[0];
       return(1);
       } else { return(0); }
    }
    I'm thinking......

  4. #4
    Join Date
    Feb 2006
    Posts
    56
    this thread is over two years old, why drag it back up?

  5. #5
    Join Date
    Jul 2005
    Location
    UK, England
    Posts
    14
    because the last time I logged in to this forum was probably about 2 years ago and I could not reply to or create any posts because of some stupid message saying I hadn't contributed anthing to the forum.

    I simply replied to this post just to get rid of the stupid message everytime I logged in......................huh
    I'm thinking......

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •