Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
My personal favorite DB application design model is OOP. I usually end up making an object with the same field names as the database table to represent each object.

pseudo: package Project::User; my @FIELDS = qw /name age sex passwd/; sub new { my $type = shift; my $dar = shift or return undef; # data array ref, usually # a fetchrow_arrayref if (ref $dar = array) { # they already pulled the data, we're just holding # it for display or an update } elsif ($dar =~ /^\d+$/) { # if it's a unique ID, pull the data from the db } else { # it's just empty, we're empty } my %init = (); my @init{ @FIELDS } = @$dar; } sub pullFromDB { my $self = shift; my $uid = shift or return undef; # sql code to pull from DB } sub dbSync { my $self = shift; # db commit stuff here } sub assignArgs { my $self = shift; # utility function to assign data values to object properties }
... ok that's a bit much to write out, but I hope it presents the basic ideas I've used. Usually the object is used like

$user = new Project::User($uid); or $user = new Project::User($sql->fetchrow_arrayref); It makes it very easy to operate on the front-end. Or perhaps it's just needlessly complex :P


In reply to OOP + RDBMS == :D by simeon2000
in thread How to structure applications using a RDBMS by dragonchild

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (6)
    As of 2015-07-02 23:36 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (47 votes), past polls