Cake allows you to connect to an unlimited number of databases in a
single application session/request. To change the target of one
database connection you can do the following:
$db = ConnectionManager::getDataSource("default"); // Get a reference
to the default database
$db->reconnect(array("database" => "new_db", "host' =>
"192.168.168.99")); // Connect to a different database on a different
server
You can also use multiple database connections in parallel, and
dynamically switch which one a model is connected to:
$this->Model->findAll(...); // Run a query
$this->Model->setDataSource("other_connection"); // Switch to a
different database connection
$this->Model->findAll(...); // Run another query
$this->Model->setDataSource("default"); // Switch back to the original
database connection
You can add additional database connections by copying the $default
variable in /app/config/database.php and renaming it.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---