[Dbix-class] Multiple connections

Spevak, Martin (HPES Network Management Solutions) martin.spevak at hp.com
Thu Jan 16 12:05:16 GMT 2014


I am not sure, if you need this, but try:

------ [ run.pl ] -------------
use Project::DBIx;
use Project::Config qw/$config/;

my $db1 = Project::DBIx->connect(
        $config->{'db'}->{'dbi_dsn'},
        $config->{'db'}->{'username'},
        $config->{'db'}->{'password'},
        {AutoCommit => 1},
        ) or die "error connecting to DB\n";

my $db2 = Project::DBIx->connect(
        $config->{'db'}->{'dbi_dsn'},
        $config->{'db'}->{'username'},
        $config->{'db'}->{'password'},
        {AutoCommit => 1},
        ) or die "error connecting to DB\n";

--- [ Project::DBIx.pm ] ----

use base 'DBIx::Class::Schema';
use Project::Config qw/$config/;
__PACKAGE__->load_namespaces();

sub connect {
    my $self     = shift;
    my @params   = @_;

    #when no parameters set, use the once from configuration file
    if (@params == 0) {
        @params = (
            $config->{'db'}->{'dbi_dsn'},
            $config->{'db'}->{'username'},
            $config->{'db'}->{'password'},
            {
                AutoCommit => 1,
                LongReadLen   => 2147483647,
                LongTruncOk   => 1,
            },
        );
    }

    my $connection = $self->SUPER::connect(@params);  
    return $connection;
}

------ [ Project::DBIx directory ]----
DBIx/Result
  ... schema def ...
DBIx/ResultSet
  ... schema def ...


I hope, it helps.

Martin

On Thu, 2014-01-16 at 11:54 +0000, Dave Howorth wrote:
> Hernan Lopes wrote:
> > i guess you are using catalyst dbix models.
> 
> No I'm not using Catalyst. I want to make two connections to the same
> database in the same application. My question was correct, I think.
> 
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk

-- 
Martin Spevak
HPES Software Development Engineer
HPES Network Management Solutions
Location:  Galvaniho 7A, Bratislava, Slovakia
Tel:     +421 2 5752 5574
Email:martin.spevak at hp.com
Out of Office Alert:  




More information about the DBIx-Class mailing list