RE: [PEAR] a slightly harder question

From: Date: Fri, 25 Feb 2005 23:51:04 +0000
Subject: RE: [PEAR] a slightly harder question
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-17691@lists.php.net to get a copy of this message
> -----Original Message----- > From: Justin Patrin [mailto:papercrane@gmail.com] > Sent: Friday, February 25, 2005 11:13 AM > To: Sasha Sklar > Cc: pear-general@lists.php.net > Subject: Re: [PEAR] a slightly harder question > > On Thu, 24 Feb 2005 17:57:40 -0800, Sasha Sklar > <Sasha.Sklar@craveonline.com> wrote: > > I've been working at this new job for about 4 days, and they've just > > dropped a doozy on me. > > > > All reads are performed on one database, and all writes are performed on > > another. The writes are then pushed to the read db by a server process. > > > > So basically, all operations performed with the get(), find(), fetch(), > > count(), etc go to DB1, and all uses of update(), delete(), insert(), > > etc go to DB2. > > > > So, I figure I can basically have two sets of identical DataObject > > classes, one for reading and one for writing. But I'm having trouble > > figuring out how to configure them. Or could I simply have the two > > databases in the config file, but can it handle db's with identical > > tables? > > > > I'm sorry that I keep coming to you guys, I'd much rather figure stuff > > out on my own, but I kinda got blindsided by this issue. Any suggestions > > are appreciated. > > > > You don't need 2 sets of DataObject classes. This would be a > nightmare. I use a *very* simple system for something similar (dev vs. > live DBs). I have one db.ini and db.links.ini file and symlink the > db2.ini and db2.links.ini files to them. Then I have 2 DataObject.ini > files, oone for each DB. The DOs don't care what DB they're on, you > just have to set your DSN correctly. > > And since you're using 2 DBs of the same name (I assume) you should > only need 2 DataObject.ini files with different hosts in the DSN. > > The problem you'd face with this is that you can connect to one *or* > the other. I really have no idea how you'd connect to 2 DBs with the > same DB name on different hosts with DB_DataObject in the same script. > > -- > Justin Patrin > > -- > PEAR General Mailing List (http://pear.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php Just an update, not being able to read and write in the same script was something I didn't want to face so I tried this: I created two dummy classes that extend DB_DataObject: DB_DataObject_Read and DB_DataObject_Write. The documentation suggested you could do this if you needed extra functionality. I figured I could use it to make an end run around my problem. So I have two files, DataObjectRead.php and DataObjectWrite.php, which contain this: require_once "DataObject.php"; class DB_DataObject_Write extends DB_DataObject { } With Read instead of Write for the other. And I had two separate database.ini files (the config files) with extends and extends location set. And it almost worked, except that I realize that I would have to have two separate sets of dataobjects because each data_object has to extend either the read or write class. I was hoping there would be some way to have two separate instances of DataObject on a page without having two sets of each class, but it seems less likely.

« previous php.pear.general (#17691) next »