Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: [DBIx::Class] Can I extract $dbhandle from schema?

by LTjake (Prior)
on Aug 21, 2007 at 11:04 UTC ( #634053=note: print w/replies, xml ) Need Help??

in reply to [DBIx::Class] Can I extract $dbhandle from schema?

I belive you can access the $dbh via the Storage class:

my $dbh = $self->schema->storage->dbh;

"Go up to the next female stranger you see and tell her that her "body is a wonderland."
My hypothesis is that she’ll be too busy laughing at you to even bother slapping you.
" (src)

Replies are listed 'Best First'.
Re^2: [DBIx::Class] Can I extract $dbhandle from schema?
by dreel (Sexton) on Aug 21, 2007 at 12:41 UTC
    Great! 10x! It's working! DBIx creates connection at every query? Or it uses sheared dbhandle? May be you read it before me )
      DBIx::Class re-uses existing connections. It checks if connections are still open: if so they are re-used otherwise it reconnects.

      Please note DBIx::Class is not sharing connections: every my $schema = My::DB->connect('dbi:mysql:DB', 'user', 'secret_password'); will remain separate from every other connection, but every query within an individual $schema will re-use the same connection as long as it is still open. Connections only get closed when the script finishes or when explicitly closed ($schema->disconnect;) or when timed-out server-side.


      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

        Sorry, thought I was logged in. This applies to the post above. I also tried using Apache::DBI and it didn't seem to work and I have since read this is not recommended either. Is that not a good solution?
        I am using DBIx::Class and when I look at the processlist (mysql) all the connections are in state of sleep. I am using mod_perl so the scripts should be staying alive. Is it recommended to call disconnect each time or to try and re-use the existing connection?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://634053]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2018-06-19 04:01 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (111 votes). Check out past polls.