No, but what you might try is writing a subclass of DBI:
package myDBI; use DBI; our @ISA = qw(DBI); sub connect { my $proto = shift; my $class = ref($proto) || $proto; my $dbh = $class->SUPER::connect(@_); bless $dbh, "${class}::db"; } package myDBI::db; our @ISA = qw(DBI::db); sub prepare { my $dbh = shift; my $sth = $dbh->SUPER::prepare(@_); $sth->{private_MyDBI_dbh} = $dbh; $sth; } package main; my $dbh = myDBI->connect('dbi:Drivername:dbname', 'user','passwd',{RaiseError=>1}); my $sth = $dbh->prepare("select stuff from table"); my $dbh_copy = $sth->{'private_MyDBI_dbh'};
Then you would also have to write a prepare() method to save the db handles in the statement handles using a 'private_*' attribute name (see the DBI docs). You could make it transparent except for the initial connect. Don't ask me if this'll work though, I've never tried it :)

Update: Fixed code. DBI->connect actually returns a DBI::db object. Oh what the heck, I wrote the prepare method also. All completely untested.


In reply to Re: Help me to not have to rewrite everything I've done for the past few weeks by runrig
in thread Getting db handle from statement handle with DBI by drobnox

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.