For Programmers: Free Programming Magazines  


Home > Archive > PHP Pear > September 2005 > Re: [PEAR] DB_DataObject









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [PEAR] DB_DataObject
Justin Patrin

2005-09-28, 6:58 pm

On 9/28/05, steven scott <stevenjscott@gmail.com> wrote:
> Hello,
>
> I have a couple of questions about DB_DataObject. I am a developer
> putting together a rather large website and we need some serious data
> abstraction to clean things up.
>
> We have master and slave databases and we do all the writing to the
> master and reads all come from the slaves. (usually) Is there a way
> to set up two database objects one to read from and one to write from
> automatically within the DB_DataObject class.


No. DB_DO assumes one DB connection is going to be used for
everything. You'd have to hack into the update() and insert() methods
and make them use a different connection for changing data.

Or you could, based on the page and request vars, use a different DSN
if the script you're running is going to alter data. This would be the
best solution IMHO. Default to the slave and use the master when a
script is updating data.

>
> Also if we already have a pear::DB object instantiated is is possible
> to just use that object instead of creating another connection to the
> db. We try to keep one connection open across the application. To
> limit the connection times.
>


No, at least not directly. I suggest going the other way. Instantiate
a DO then get the DB connection from it to use for your other stuff.
See DB_DataObject::getDatabaseConnection(). Of course, you shouldn't
really need that anyway...you can do almost everything from within
DB_DO directly.

--
Justin Patrin
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com