RE: DB_DataObject and multiple databases

From: Date: Tue, 29 Apr 2008 23:53:20 +0000
Subject: RE: DB_DataObject and multiple databases
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-28847@lists.php.net to get a copy of this message
I have a multi databse solution working for my job. Here is the general strategy when working with DB DataObjects. In your ini file you can set up multiple database connection with : database_xxx = mysql://user:pass@localhost/db_xxx database_yyy = mysql://user:pass@localhost/db_yyy ini_xxx = /usr/local/project/databojects/xxx.ini ini_yyy = /usr/local/project/databojects/yyy.ini Here is the problem, I don't know how to setup DataObject to allow mulitple values for these variables: schema_location = /usr/local/project/DataObjects class_location = /usr/local/project/DataObjects require_prefix = DataObjects/ class_prefix = DataObjects_ It means createTables will dump all your dataobjects from all your databases into he same directory. You however are smart and want a clean separation between database directories. If there are no table name collisions then I wouldn't bother, no workaround necessary. Problem is that DB_DataObjects factory method uses the class_location value (loaded into memory when dataobjects starts up) so it won't know how to auto-include your file for instantiating any of your objects if they aren't in the same directory. We had to do these annoying things to work around this: 0) Manually include() each DBDO file you are interested in, and call all the constructors youself when you want them. Don't let DB_DataObject auto anything for you. 1) Each time your run createTables you must go in an alter the schema and class location variables to the one databases directory you want. Then comment out all the databases you are not interested in. Then run the script, which will only generate that files for one db in the desired director. Even if you do this you will not be able to use the DB_DataObject::factory method as it will still not know where to load objects from. 2) Alternative: Create several database.xxx.dbdo.ini scripts each with specific instructions on building objects for each database. Alter createTables to search a directory for *.dbdo.ini and run each seperately. You will still need one main .ini file for accessing them all. 3) Actually go into the $_GLOBALS['DBDO_STUFF']['loaded_from_ini_file'] and change array values by hand depending on which set of object your want to play with. Or rather, just as if you are setting up DB in the first place, call parse_ini_file() on your separate files each time you are using an object from a different database. This solution is rather stupid as it can lead to all sorts of problems and overhead, but we have done so in some situations. It would be REAALLY nice if DB_DataObjects itself were to allow multiple class_location variables like they allow mulitple database_ ones. -Dan -----Original Message----- From: Mike D'Ambrogia [mailto:miked@jamagination.com] Sent: Sunday, April 27, 2008 12:47 PM Cc: pear-general@lists.php.net Subject: Re: DB_DataObject and multiple databases can anybody provide any insight on this? On 4/22/2008 7:54 AM, Mike D'Ambrogia wrote: > I'm working on a migration project taking the data from an early > version of an modified application in db1 and migrating it into a > current version of the unmodified application on db2, like to figure > out how to use dbdo to work with this so that I can massage the data > into db2 as I go along > > each database instance is on a separate system with different > connection strings and login params. the database names are > different, but the table names are very similar with most names > matching between each db > > I've been able to setup createtables.php to produce 2 dataobjects > folders, one holding classes for the abstractions of db1 and the other > for the abstraction of > db2 (./includes/dataobjects_1.5.8 and ./includes/dataobjects_1.12) > > I configured createtables to generate the classes with a class name > prefix > (class_prefix) to help keep the tables that share the same names in > db1 and db2 unique (DataObjects158_table1 and DataObjects112_table1, > etc) > > hope that background makes sense... > > so far so good > > my problem is trying to figure out how to setup the environment to > expose both database to the calling code at once > > in > > http://pear.php.net/manual/en/package.database.db-dataobject.intro-con > figuration.php, when discussing multiple databases, the dbdo docs > states: > > /database_*/ string > > When you have multiple databases you can use the database_* to specify the > DSN <http://pear.php.net/manual/en/package.database.db.intro-dsn.php> for > each database > > When you have multiple databases you can use the table_* configuration > variables to map individual tables to different databases<...snip> > > > the example is thin on specifics or a viable example, and I cannot > find any reference to the table_* configuration variable. > > any pointers? > > thanks in advance for the help > > mike > This e-mail message is for the sole use of the intended recipient(s) and may contain confidential and privileged information of Transaction Network Services. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message.

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