Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re^3: custom $dbh with Rose::DB?

by mreece (Friar)
on Nov 07, 2006 at 15:48 UTC ( #582677=note: print w/replies, xml ) Need Help??

in reply to Re^2: custom $dbh with Rose::DB?
in thread Why did DBIC overtake CDBI?

using $db->dbh as a setter isn't documented, but this approach sounds reasonable if i can get it to work.

this is my test script so far, which is not working:

use DBI; use Rose::DB; my $dbh = DBI->connect( 'DBI:mysql:database=mydb', 'user', 'pass' ); my $rdb = Rose::DB->new( driver => "mysql" ); $rdb->dbh( $dbh ); print "still here\n";
No database information found for domain 'default' and type 'default' at line 6
what do i do here instead if i don't want to do the register_db stuff(or can't, because in the non-simplified case i don't have the DSN, only a $dbh that was exported from elsewhere) ?


it looks like this works, clunky as it seems:

use base qw( Rose::DB ); __PACKAGE__->use_private_registry; __PACKAGE__->register_db( driver => 'mysql', database => 'fake', host => 'fake', username => 'fake', password => 'fake' ); package My::RDBO::User; use base qw( Rose::DB::Object ); use DBI; __PACKAGE__->meta->setup( table => 'user', columns => [qw( id username password email name )], pk_columns => 'id', unique_key => 'username', ); sub init_db { my $dbh = DBI->connect( 'DBI:mysql:database=mydb', 'user', 'pass' +); my $rdb = My::RDB->new; $rdb->dbh($dbh); return $rdb; } package main; my $u = My::RDBO::User->new(id => 1); $u->load; print("$_ => ", $u->$_, "\n") foreach $u->meta->columns;

Replies are listed 'Best First'.
Re^4: custom $dbh with Rose::DB?
by siracusa (Friar) on Nov 07, 2006 at 18:18 UTC
    using $db->dbh as a setter isn't documented, but this approach sounds reasonable if i can get it to work.

    Whoops, yeah, I'll go document that now. Anyway, as you discovered, you have to register at least one data source to instantiate a Rose::DB object. You don't actually have to provide all the information that you did, however. In most cases, just specifying a driver will work.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://582677]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2023-01-28 03:06 GMT
Find Nodes?
    Voting Booth?

    No recent polls found