| 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
|