Wally Hartshorn has asked for the wisdom of the Perl Monks concerning the following question:
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)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Different Database Permissions Using Class::DBI
by perrin (Chancellor) on Jul 02, 2003 at 15:57 UTC | |
by Anonymous Monk on Jul 02, 2003 at 20:41 UTC | |
by perrin (Chancellor) on Jul 02, 2003 at 21:18 UTC | |
|
Re: Different Database Permissions Using Class::DBI
by simon.proctor (Vicar) on Jul 02, 2003 at 15:45 UTC | |
|
Re: Different Database Permissions Using Class::DBI
by bilfurd (Hermit) on Jul 02, 2003 at 17:47 UTC | |
|
Re: Different Database Permissions Using Class::DBI
by cleverett (Friar) on Jul 02, 2003 at 22:04 UTC | |
|
Re: Different Database Permissions Using Class::DBI
by aquarium (Curate) on Jul 02, 2003 at 21:54 UTC |