Dynamic DSN w/ Class::DBI Exampleby gryphon (Abbot)
|on Apr 23, 2004 at 20:46 UTC||Need Help??|
gryphon has asked for the wisdom of the Perl Monks concerning the following question:
Greetings fellow monks,
I've been trying unsuccessfully to play with Class::DBI using a dynamic DSN passed to my class at runtime. I've been Googling for hours, and I haven't come up with much to show for it. Does anyone have some example code they could share for how to get this done?
This is basically what I'd like to accomplish, but it doesn't work. (Please pardon my lack of POOP knowledge/experience.)
Why do I even want to do this? Well, I have multiple databases all with the same schema. I'd like to have only one Class::DBI module to avoid replicating code. And I'd like to pass in the database name, username, and password from an INI file since that's where just about all other configuration data is stored.
Now, I've tried the following:
...and of course this works well, but it will only work for very simple models. I won't be able to edit the automatically created classes, so it doesn't work for more complicated cases such as where I'm joining together several tables or want to muck around with output or whatever.
Sorry if this is a stupid question. I've been reading docs all day and haven't been able to figure this out.