Re: do pear packages create their own seperate DB connections?
| From: | Jeroen Houben | Date: | Tue, 22 Apr 2003 20:16:46 +0000 |
| Subject: | Re: do pear packages create their own seperate DB connections? | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-15351@lists.php.net to get a copy of this message | ||
> On Tue, 2003-04-22 at 21:09, Wolfram Kriesing wrote:
>> Jeroen Houben wrote:
>> >>But to try to answer your question, I think what you want to do
>> >>might be:
>> >>
>> >>if (do i need a DB-connection?) {
>> >> $db = DB::connect();
>> >> do DB stuff
>> >>} else {
>> >> get data/results or do action without
>> >> the need of using db-data
>> >>}
>> >>
>> >>i hope i could explain what i mean :-)
>> >>
>> >
>> >
>> > Yes it is, but I'm afraid *I* couldn't explain what *I* mean :-)
>> > I'll take your example from above and change it to what I mean.
>> > Maybe what I'd like to see is not possible but at least we'll be
>> > talking about the same thing.
>> > if (do i need a DB-connection?) {
>> > if (there is an instance of (M)DB 'out there' for the given DSN)
>> > {
>> > // use it
>> > } else {
>> > $db = DB::connect(DSN);
>> > do DB stuff
>> > }
>> > } else {
>> > get data/results or do action without
>> > the need of using db-data
>> > }
>> >
>> > Hope that makes it clearer. I think Lukas mentioned this in one of
>> > his
>>
>> yes, Lukas mentioned it. It's the singleton ... and he wrote that he
>> is thinking about putting it into MDB
>> what i do in my appls is the following to implement the singleton
>>
>> class x
>> {
>> function &getInstance()
>> {
>> $varName = '__'.__CLASS__;
>> if (!isset($GLOBALS[$varName]) ||
>> get_class($GLOBALS[$varName])!=__CLASS__) {
>> $GLOBALS[$varName] =& new x();
>> }
>> return $GLOBALS[$varName];
>> }
>> }
>>
>> this way it gets saved in the global namespace, i know. its not really
>> cool. but may be someone knows a better and nicer way
>> or is it even simpler with php4?
> Is there a problem with statics? That's a serious question... I thought
> from reading the docs they're in v4, but I'm not certain.
>
> Jon
>>
Ik haven't used the singelton pattern, but I've read about it:
http://www.horde.org/papers/kongress2002-design_patterns/11_singleton_impl.xml.html
HTH
- Jeroen