Dynamically change data source of models

2009-08-13 Thread Fritsie

Hello,
I'm developing an application which will be used by multiple companies
and I want to use a shared database for common information like users,
companies, permissions etc, but I want to use a separate database for
each company for their own (private) information. The reason to give
every company an own database is for speed, security en taking
advantage of the caching from the database.

I've read the article by Anssi Rajakallio (doze) at the Bakery:
http://bakery.cakephp.org/articles/view/use-multiple-databases-in-one-app-based-on-requested-url
And also the comments of the cakephp team, but I still have a few
problems.

I don't want to initialize a connection to 1 company-database (the
solution of Anssi) at the start, but I want to be able to change from
data source while making one request, for instance when I want to
benchmark multiple companies I need to make one request, and multiple
database requests on different databases (depending on the companies I
want to benchmark).


The question is how I can change dynamically the data source of all
the models who don't use the 'shared' data source.


Thanks in advance.
Regards,
Raymond

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Dynamically change data source of models

2009-08-13 Thread CobaltShark

I use Ad-hoc joins to LEFT JOIN data from different databases using
the same default db config and it works well. Just specify table =
'common_db_name.table_name' . You will obviously need to ensure that
the db user specified in your config has at least SELECT privs to both
databases. I usually give Any user on localhost SELECT privs on my
common database, but you could just as easily grant database specific
as well.

On Aug 13, 5:11 am, Fritsie steff...@gmail.com wrote:
 Hello,
 I'm developing an application which will be used by multiple companies
 and I want to use a shared database for common information like users,
 companies, permissions etc, but I want to use a separate database for
 each company for their own (private) information. The reason to give
 every company an own database is for speed, security en taking
 advantage of the caching from the database.

 I've read the article by Anssi Rajakallio (doze) at the 
 Bakery:http://bakery.cakephp.org/articles/view/use-multiple-databases-in-one...
 And also the comments of the cakephp team, but I still have a few
 problems.

 I don't want to initialize a connection to 1 company-database (the
 solution of Anssi) at the start, but I want to be able to change from
 data source while making one request, for instance when I want to
 benchmark multiple companies I need to make one request, and multiple
 database requests on different databases (depending on the companies I
 want to benchmark).

 The question is how I can change dynamically the data source of all
 the models who don't use the 'shared' data source.

 Thanks in advance.
 Regards,
 Raymond
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---