Zend_Db -- Singleton implementation as in Zend_Log?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Zend_Db -- Singleton implementation as in Zend_Log?

Axel Christ
Hi there, are there any plans of implementing the singleton pattern in
Zend_Db? To have the possibility of connecting to different dbs at the
same time it could be done as it is implemented in Zend_Log... Or should
I handle my db connections in a different way when using the Zend framework?

Regards

Axel Christ
Reply | Threaded
Open this post in threaded view
|

Re: Zend_Db -- Singleton implementation as in Zend_Log?

akrabat
Axel Christ wrote:
> Hi there, are there any plans of implementing the singleton pattern in
> Zend_Db? To have the possibility of connecting to different dbs at the
> same time it could be done as it is implemented in Zend_Log... Or should
> I handle my db connections in a different way when using the Zend
> framework?
>

I stick my $db into the registry:

    $db = Zend_Db::factory($adapter, $config);
    Zend::register('db', $db);


Then when I need it again:

    $db = Zend::registry('db');


Regards,

Rob...
Reply | Threaded
Open this post in threaded view
|

Re: Zend_Db -- Singleton implementation as in Zend_Log?

Sergej-2
In reply to this post by Axel Christ
Axel Christ wrote:

> Hi there, are there any plans of implementing the singleton pattern in
> Zend_Db? To have the possibility of connecting to different dbs at the
> same time it could be done as it is implemented in Zend_Log... Or
> should I handle my db connections in a different way when using the
> Zend framework?
>
> Regards
>
> Axel Christ
>
I guess using Zend::registry() instead instead of writing a singleton
interface for every class is much easier

--
http://www.mif.vu.lt/~sean3322/other/signature

Reply | Threaded
Open this post in threaded view
|

Re: Zend_Db -- Singleton implementation as in Zend_Log?

Axel Christ
In reply to this post by akrabat
Rob Allen wrote:

> Axel Christ wrote:
>  
>> Hi there, are there any plans of implementing the singleton pattern in
>> Zend_Db? To have the possibility of connecting to different dbs at the
>> same time it could be done as it is implemented in Zend_Log... Or should
>> I handle my db connections in a different way when using the Zend
>> framework?
>>
>>    
>
> I stick my $db into the registry:
>
>     $db = Zend_Db::factory($adapter, $config);
>     Zend::register('db', $db);
>
>
> Then when I need it again:
>
>     $db = Zend::registry('db');
>
>
> Regards,
>
> Rob...
>
>  
Hi Rob, thanks for pointing me in the right direction there.