eZ Community » Forums » Developer » Separate database for custom objects?
expandshrink

Separate database for custom objects?

Separate database for custom objects?

Monday 01 October 2007 6:07:24 pm - 3 replies

Hello!

I'm currently building a module in which I've been planning to extend the eZPersistentObject class to store data in custom database tables. To better separate this extension from the eZ installation, I want to use a separate database for these (about 10) tables.

However, I can't figure out how to utilize a second database from within the eZPersistentObject framework, if at all possible?

I'd appreciate any thoughts on this, perhaps there's a better way?

Monday 01 October 2007 8:07:46 pm

Hi,

I haven't tried this, I have never seen why to put custom tables in a separate database, as keeping on the same database has no problem regarding ezpersistentobject

Nevertheless, I guess this

eZPersistentObject gets Ezpublish current database instance calling ezDB class like

  $db =& eZDB::instance();  

eZDB has a method to set Ezpublish current database instance , so calling it should do the trick

 

//get ezpublish current instance
$ezdb =&  eZDB::instance();  

//create your database instance 
$mydb =&  eZDB::instance( ..., $yourdatabaseparameters, $forceNewInstance=true);  

//set it as default 
eZDB::setInstance( $mydb );  

//from here any call to ezpersistent will use your database instance  
....

/don't forget to restore ezpublish database instance
eZDB::setInstance( $ezdb );  

Basically , it keeps switching between ezpublish database, and your custom database

Tuesday 02 October 2007 8:35:36 am

Hi guys

I once had to connect to a custom MS SQL database (read-only access) to show some data of it on our eZ Publish site. To be able to use eZPersistentObject for this a hack was required. You can find a patch at http://issues.ez.no/10667. Be careful, this is only tested for reading external data, but normally it should also work for modifying the external database. Let me know if you have problems using it. Good luck!

Tuesday 02 October 2007 5:43:21 pm

Thanks very much, Kristof!

I tested your patch for fetching some data and it worked like a charm. At some point, we'll need to write data back to the database, I'll keep you posted on the progress happy.gif Emoticon

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from