Certainly it is possible to embed that code within object initializers. The question is whether there is any pressing need to store the DB connection within an object. In building your object model I would reflect on a few issues:

  1. Do you want to standardize startup/shutdown behavior across multiple scripts/CGIs? Say, a flag for reusing handles during instantiation and autocommit code in the absence of any errors at closing. This could go into the constructor and DESTROY methods, respectively. If not, BEGIN and END blocks will suffice.

  2. Will other code in your CGIs require access to the DB handle? Do you want to have to request a reference from an object, or would it be more handy to store the handle somewhere like $main::db?

  3. How will user access be restricted and monitored? It will be critical to provide a strict programming interface to your table as opposed to allowing your customers direct access to your table via SQL, even if they are trusted parties. You'll probably want something like a 'User' module with accessors, mutators, and a 'save' method. If you decide to head in this direction, you'll almost certainly be better off keeping the DB connection object separate from any logic modules for manipulating table data.

HTH, fever


In reply to Re: Object DBI concepts by djantzen
in thread Object DBI concepts by Angel

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.