Hi. First off, don't ever, ever, ever post passwords! >:(

Having gotten past the obligatory chastising i will now assume that you would like to see some kind of Object Oriented example of the code you have provided. Would you settle for a discussion instead?

First off, OO has been available to Perl since version 5, and yes, you do need modules/packages to define Objects.

Second, what is 'Objects::MySQL'? There is no CPAN module by that name (nor any namespace for 'Objects'), so (again, assuming because i have not seen the post in question) i would say that the author might have 'hand-rolled' a Database wrapper class named Objects::MySQL.

Why would one want to do this? Well, in small scripts i think wrapping DBI into _another_ OO interface tends to be overkill, there is not a lot to gain from it and you still type just as much on the whole. Oh yeah, instead of appending die to each and every DBI method call like you do above, just tell DBI to handle die'ing for you:

my $dbh = DBI->connect( "DBI:mysql:$dbname",$login,$password, { RaiseError => 1 }, ); my $sth = $dbh->prepare('SELECT * FROM catalog'); $sth-> execute();
But again, why would one want to wrap DBI? Abstraction is one good reason. There is a concept called N-Tier which describes how to design component based, scalable applications. If you want to find out more, just search the web - but try to avoid the marketing whatis.com has a good starting point with 3-tier application.

Ease is another reason. DBIx::XML_RDB and DBIx::XHTML_Table are two CPAN modules that wrap DBI into another OO interface to provide a user with a way to return the DBI results transformed 'behind the scenes' into XML or an XHTML table respectively (and yes, this reason is really just abstraction in disguise). Both modules accept the database connect info and a SQL statement, but they do not require (or even allow) the user to fetch the rows. Instead, one string containing all the data is returned, wrapped in XML or table tags.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
F--F--F--F--F--F--F--F--
(the triplet paradiddle)

In reply to (jeffa) Re: use Objects:: MySQL ? by jeffa
in thread use Objects:: MySQL ? by david.jackson

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, 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.