This is probably blindingly obvious to most people, but I'm mystified. I'm working on my first project to use Class::DBI, accessing a MySQL database.

This project will consist of two CGI programs -- the query program, which will be used by the general public to view information from the database; and the update program, which will be used by staff to enter information into the database.

The database access used by the query program presumably should be limited to "select" permissions, while the database access used by the update program will need additional permissions (select, insert, delete).

My problem is this: How do I use Class::DBI to provide both types of access?

Here is the class for public (read-only) access:

package MyDB; use base 'Class::DBI'; __PACKAGE__->set_db('Main', 'dbi:mysql:mydb', 'public', 'password'); 1;

Here is the class for staff (read/write) access:

package MyDBUpdate; use base 'Class::DBI'; __PACKAGE__->set_db('Main', 'dbi:mysql:mydb', 'staff', 'password'); 1;

Here is (part of) a class for one of the six tables:

package Person; use base 'MyDB'; __PACKAGE__->table('person'); __PACKAGE__->columns(All => qw/ first_name last_name street city state zip /); 1;

My fear is that, for each of my tables, I need to create a class like this:

package PersonUpdate; use base 'MyDBUpdate'; __PACKAGE__->table('person'); __PACKAGE__->columns(All => qw/ first_name last_name street city state zip /); 1;

This would mean duplicating the information for each table, which doesn't seem right. I'm hoping there is something I'm missing. Can someone show me what it is? (Or am I being too paranoid by using a read-only account for public access and a read-write account for staff access?) I did some poking around in Super Search, but didn't find the answer to this. (Or I found it and didn't realize that I had done so!)

While writing this question, I did one last poke around Google and might have found the answer. Perhaps what I need to do is delete MyDBUpdate and instead, for each table, create a class like this:

package PersonUpdate; use base 'Person'; __PACKAGE__->set_db('Main', 'dbi:mysql:mydb', 'staff', 'password'); 1;

Does that sound right? (Presumably the user ID and password would be pulled from a config file rather than hard-coded in a half-dozen different source files.)

Also, while we're on the subject of Class::DBI, can someone point me to some good tutorials? I've found a few to get me started, but I'd like some more. The ones I've found include:

Are there others that are recommended reading?

Wally Hartshorn

(Plug: Visit JavaJunkies, PerlMonks for Java)


In reply to Different Database Permissions Using Class::DBI by Wally Hartshorn

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.