On Fri, Oct 21, 2011 at 7:52 AM, Roland Philibert <[email protected]>wrote:

>
> Hi all,
> Could anybody send me an example on how to connect multiple databases
> using DBIC::Schema?
>
> I have:
>
> package MyApp::Model::DB;
>
> use strict;
> use base 'Catalyst::Model::DBIC::Schema';
>
> __PACKAGE__->config(
>    schema_class => 'MyApp::Schema',
>
>    connect_info => {
>        dsn => 'dbi:mysql:database=db1:host=host1',
>        user => 'root',
>        password => 'root',
>    }
> );
>
> And I need to connect to another mysql db (db2) under a different host
> (host2)
>
>
[assuming catalyst app]

Create a second model  MyApp::Model::DB2 with connection info for the second
db.  I autocreate them using...

# create/update model for netadmin db
script/netadmin_create.pl model *DB* DBIC::Schema NetAdmin::Schema
create=static components=TimeStamp
'dbi:Pg:dbname=netadmin;host=hostname;port=5432' 'username' 'password' '{
AutoCommit => 1, quote_char => q{"}, }'

# create/update model for radius db
script/netadmin_create.pl model *RadiusDB* DBIC::Schema
NetAdmin::RadiusSchema create=static components=TimeStamp
'dbi:Pg:dbname=radius;host=hostname2' 'username2' 'password2' '{ AutoCommit
=> 1 }'

Then I use one connection using $c->model('*DB*::Table')->...  and the other
using $c->model('*RadiusDB*::OtherTable')->...

Don't know if this is the best way, but it's what I use?!!



-- 
Steve Rippl
Technology Director
Woodland Public Schools
360 841 2730
_______________________________________________
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/[email protected]

Reply via email to