Separate database for custom objects?

Author Message

Torbjørn Myhre

Monday 01 October 2007 9:07:24 am

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?

Lazaro Ferreira

Monday 01 October 2007 11:07:46 am

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

Lazaro
http://www.mzbusiness.com

Kristof Coomans

Monday 01 October 2007 11:35:36 pm

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!

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Torbjørn Myhre

Tuesday 02 October 2007 8:43:21 am

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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 31 2025 03:40:58
Script start
Timing: Jan 31 2025 03:40:58
Module start 'layout'
Timing: Jan 31 2025 03:40:58
Module start 'content'
Timing: Jan 31 2025 03:40:58
Module end 'content'
Timing: Jan 31 2025 03:40:58
Script end

Main resources:

Total runtime0.0182 sec
Peak memory usage4,096.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0044 588.1563151.2109
Module start 'layout' 0.00440.0028 739.3672220.6875
Module start 'content' 0.00720.0097 960.05471,001.9297
Module end 'content' 0.01690.0013 1,961.984433.9922
Script end 0.0182  1,995.9766 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002312.7786140.0002
Check MTime0.00105.5446140.0001
Mysql Total
Database connection0.00073.641910.0007
Mysqli_queries0.001910.205330.0006
Looping result0.00000.044510.0000
Template Total0.00105.510.0010
Template load0.00084.317610.0008
Template processing0.00021.186510.0002
Override
Cache load0.00052.905910.0005
General
dbfile0.00031.761380.0000
String conversion0.00000.032740.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs