Re: MDB2: How to use two separate DSNs?
| From: | Justin Patrin | Date: | Thu, 04 Jan 2007 18:51:33 +0000 |
| Subject: | Re: MDB2: How to use two separate DSNs? | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-26252@lists.php.net to get a copy of this message | ||
On 1/4/07, J. Norment <jae@platinumpsi.com> wrote:
I have an application that needs to be connected to two separate DSNs: One MySQL, another ODBC -- possibly, one right after the other. I think this rules out the singleton method of instantiating a database object, and I think connect() will need to be used, as there is no caching in the application. I plan on assigning two different DSNs to two different variables, possibly within a singleton type wrapper. Do I need to connect and destroy with every query? MDB2 isn't persistent across php pages, is it? (I don't think that is possible in a stateless environment, but I'm not sure.) The only book that I'm aware of that deals directly with PHP patterns is written in German... so I'm really not aware of what I will need to do to implement a singleton pattern in PHP in a stateless environment, nor what that entails to the database connection... Finally, I'm aware that MDB2 currently does not support ODBC -- I plan on porting that myself from MDB. Am I on the right track?singleton is meant to be used to get the same MDB2 object for the same DSN from multiple places in code in *one page run*. It does not help you to keep a connection open between requests, this is not how PHP generally works. You can use singleton to connect to 2 different DBs as it stores the connection objects based on DSN. I, however, would suggest simply using connect twice and keeping the object around yourself (if you'll be keeping the DSN around to call singleton you can just as easily keep the MDB2 object around). -- Justin Patrin