to my knowledge CakePHP handles multiple database connections quite easily.
within your /app/config/database.php file you can define multiple
connections that can then be accessed within your model.
e.g.
var $conn1 = array('driver' => 'mysql',
'connect' =>
'mysql_connect',
'host' => 'localhost',
'login' => 'user',
'password' =>
'password',
'database' => 'db_1',
'prefix' => '');
var $conn2 = array('driver' => 'mysql',
'connect' =>
'mysql_connect',
'host' => 'localhost',
'login' => 'user',
'password' =>
'password',
'database' => 'db_2',
'prefix' => '');
then within your model
var $useDbConfig = 'conn2';
is this what you mean or have I missed the point entirely??
to utilise Cake's database methods (e.g. save(), find(), etc) im
pretty sure you at least need to set the default connection settings.
what does your class do outside of what Cake offers?
if there is some additional functionality that is important you could
create a component maybe??
On 25/09/06, leea <[EMAIL PROTECTED]> wrote:
>
> I have a class that was written before cake. It accesses a database
> using mysql_connect. This class works perfectly and lot of my
> applications that i develop use this class.
>
> Im transferring this class across to cake, but unfortunately it
> confuses cake with the db connection.
>
> >From what ive read, cake only allows 1 db connection, so as soon as I
> open up any connection, it loses its previous connection, and only
> points towards my new one. This is hazardous once you go back to making
> more queries outside the custom class. (please note that useDBConfig
> isnt possible since it is a custom class)
>
> What I have noticed is that cake prepends the database to the query
> when you use the predefined functions and this causes bad links.
>
> Now back to my class, I CAN rewrite it as a model to make it work with
> cake, but this isnt very graceful since its ignoring the whole OO
> design theorom, and id have to edit the database.php on every project
> that wants to use my new model. I want to be able to plug and play
> different classes into cake without rewriting them.
>
> Do I need to rewrite this class? Or is there a better way of handling
> these different DB connections?
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---