Welcome, Guest. Please login or register.
Did you miss your activation email?
Oct. 06, 2008, 05:49:06 PM
47570 Posts in 10432 Topics by 5322 Members
Latest Member: euofulano
News: PRADO 3.1.1 is released!
 
The PRADO Community » Prado v3.x » General Discussion » Database » Using TActiveRecord With Multiple Databases « previous next »
Pages: [1] Print
Author Topic: Using TActiveRecord With Multiple Databases  (Read 1242 times)
Zen
Senior Member
***

Karma: 7
Offline Offline

Posts: 221



View Profile WWW
« on: Mar. 08, 2007, 03:33:40 PM »

It is easy to use multiple databases in SQLMap but if I want to use ActiveRecord with more than one database how do I specify which database my ActiveRecord class is to use Huh

Lewis
Logged

jjmf
Senior Member
***

Karma: 5
Offline Offline

Posts: 221



View Profile
« Reply #1 on: Mar. 15, 2007, 04:20:45 PM »

It´s a problem I´m facing too!

I had a solution that worked before the changes made to TActiveRecord.
Before, we had to use

public static $_tablename = '`cargo`';   //table name

and that allowed one to use `dbname`.`tablename` to query a table in other databases.
That allowed to change the databse name at run time.

But now, they changed it to a CONST and it is not possible to change the database at run time anymore!

To developers: any solution to this?
I have a DB for each year (like diretor_2006, diretor_2007, etc) and depending on the year the user has selected, my TActiveRecord classes must be able to query tables in the correct database.
« Last Edit: Mar. 15, 2007, 05:22:35 PM by jjmf » Logged
Qiang
PRADO Team Leader
Administrator
Diamond Member
*****

Karma: 97
Offline Offline

Posts: 3160



View Profile
« Reply #2 on: Mar. 21, 2007, 02:31:42 PM »

public static is very similar to class constant. I don't think you will be able to change either during runtime.

To use a different database, you may override getDbConnection() in your active record class.
Logged
jjmf
Senior Member
***

Karma: 5
Offline Offline

Posts: 221



View Profile
« Reply #3 on: Mar. 21, 2007, 04:16:43 PM »

public static is very similar to class constant. I don't think you will be able to change either during runtime.

To use a different database, you may override getDbConnection() in your active record class.

When using public static it was able to change it at runtime.
Not possible using CONST.

I try your suggestion with some of my active record classes.
Anyway, I started using SqlMap creating a set of xml files for each existing year.
For some simple stuff I'll keep using ActiveRecords, while with other I'll use SqlMap.

Thanks!
Logged
wei
PRADO v3.x Developer
Diamond Member
*****

Karma: 65
Offline Offline

Posts: 2872



View Profile
« Reply #4 on: Apr. 01, 2007, 12:33:56 AM »

Quote
and that allowed one to use `dbname`.`tablename` to query a table in other databases.

This only works if the database resides on the same connection. Thus, overriding the getDbConnection() works better.
Logged
Pages: [1] Print 
« previous next »
Jump to: