Yii Framework Forum: Dynamic db connections - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Dynamic db connections Rate Topic: -----

#1 User is offline   eval 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 85
  • Joined: 25-November 08
  • Location:Athens - Greece

Posted 13 July 2009 - 05:13 AM

Hey all,

I need to dynamically change between several (large amount of) db connections.

From what i can  see in the documentation, i need to override the getDbConnection() function of each model but the main problem here is that a model doesn't exclusively belong to a db connection, i.e. a model represents a table that exists in several (if not all) databases.

Any ideas on what i should do?

Thanks in advance
0

#2 User is offline   pestaa 

  • past Yii dev member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 705
  • Joined: 07-May 09
  • Location:Hungary

Posted 13 July 2009 - 12:05 PM

I'm not sure this would solve your problem, but give this a thought.

Extend CActiveRecord::model() so it takes a parameter indicating a db connection. Before returning parent::model() implementation, it sets the corresponding connection to a protected property.

Make sure CActiveRecord::getDbConnection() will find it.
0

#3 User is offline   riccardo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 40
  • Joined: 02-March 10

Posted 03 March 2010 - 10:30 AM

It solves the problem?
Because i'm trying to do something similar...

View Postpestaa, on 13 July 2009 - 12:05 PM, said:

I'm not sure this would solve your problem, but give this a thought.

Extend CActiveRecord::model() so it takes a parameter indicating a db connection. Before returning parent::model() implementation, it sets the corresponding connection to a protected property.

Make sure CActiveRecord::getDbConnection() will find it.

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users