Greetings,
I have an odbc database class that I need to be able to connect to multiple DSN's. What would be the best method to achieve this?
Right now I have the database, user and pass properties defined in the class with constants. I'd like to just add constants for each DSN like:
define('DB1_USER', 'user');
define('DB1_PASSWORD', 'pass');
define('DB1_DSN', 'DRIVER={SQL Server};SERVER=sub.domain.com,1433;DATABASE=database');
define('DB2_USER', 'user');
define('DB2_PASSWORD', 'pass');
define('DB2_DSN', 'DRIVER={SQL Server};SERVER=sub.domain.com,1433;DATABASE=database');
Will a 'db selector' extension work? Should I declare the parent class abstract(havent worked with abstract classes yet)? Or any other suggestion?
I'm just looking for general suggestion, nothing specific, I'll figure that out, part of the learning process...
Thanks,
Matt
Object to connect to multiple DSNs
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Object to connect to multiple DSNs
I would recommend passing the connection information to the constructor. Then you can create an object per connection. If you need to wrap that you could have a Registry to hold your connection objects and access them through that.
(#10850)