Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
There's more than one way to do things
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Class::DBI is quite a simple module really, mainly you inherit it's methods and go off about your business.
SQL is no longer a problem in the way of causing minor issues with your code, so you can retrieve, create, update or do any other database modifications necessary with the greatest of ease.
The only requirements are to set up your primary index columns, and the columns you need to use for the selects in a module that inherit's from Class::DBI, and then you have total access to Class::DBI's magic.
(example of setup)
## Main class package My::DBI; use base 'Class::DBI'; my $dsn = "dbi:mysql:***"; my $user = "****"; my $passwd = "****"; __PACKAGE__->set_db('Main', $dsn, $user, $passwd); ## Second class package My::Tables; use base 'My::DBI'; __PACKAGE__->columns( Primary => qw[id] ); __PACKAGE__->columns( All => qw [ id author title date content ip ] ); __PACKAGE__->table('entries');

Other useful methods:
add_constructor
Allows you to construct an SQL query snippet and call it through your object.
Music::CD->add_constructor(new_music => 'year > ?'); my @recent = Music::CD->new_music(2000);

retrieve_from_sql
Allows you to consruct your own SQL query like so:
(NOTE: You inlining the entire WHERE clause)
my @cds = Music::CD->retrieve_from_sql(qq{ artist = 'Ozzy Osbourne' AND title like "%Crazy" AND year <= 1986 ORDER BY year LIMIT 2,3 });

Class::DBI::AbstractSearch A search class provided by Class::DBI that allows you to write arbitrarily complex searches using perl data structures, rather than SQL.
my @music = Music::CD->search_where( artist => [ 'Ozzy', 'Kelly' ], status => { '!=', 'outdated' }, );


These are just a few of the features of Class::DBI that I have found quite useful. Check the module out for yourself, it cut my development time in at least half.

In reply to Class::DBI by stonecolddevin

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
  • Outside of code tags, you may need to use entities for some characters:
            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 romping around the Monastery: (12)
    As of 2014-04-21 12:30 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (495 votes), past polls