Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Best Coding practice

by blue_cowdawg (Monsignor)
on Dec 04, 2006 at 17:08 UTC ( [id://587697]=note: print w/replies, xml ) Need Help??


in reply to Best Coding practice

      So I'm trying to figure out the best approach, when creating the object TABLE, should I put the database handler in as one of it's attributes in the new method call, and use that or everytime I use a method/sub routine of TABLE should I pass in the database handle as a parameter?

I usually create a module that does the database connections and a few other housekeeping chores and then I create modules that are derivitaves of that one. Example:

package dbObject; my is_connected=0; # important... my $dbh=undef; sub connect { | connection foo here... } sub prepare { my ($self,$sql) = @_; if ( ! is_connected) $self->connect; $self->{sth} = $dbh->prepare(....); } 1; package myTable; use vars qw / @ISA /; use dbObject; @ISA = qw/ dbObject /; #etc. 1;
and I have variations on that theme that I use. Lately rather than use DBI for my database layer I use Class::DBI::Loader which further encapulates the databse layer for me using a similar method where I have a "parent" class instantiate the loader and the "child" classes inherit it from there. In fact I'm working on a major project now that uses that methodology and other than some interesting bugs I've discovered in the way Class::DBI::Loader reacts to certain table names I've not had any problems.

Hope this helps...

UPDATE:Special thanks to GrandFather for pointing out my fat-fingering


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-25 06:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found