1. It is just not possible to do this, unless the one mysql
connection has permission to access both databases (ie same database
server, same user/pass).
2. If the permissions are ok, then you can do a join across databases
by prefixing the database name, eg
SELECT User.* from database1.users as User LEFT JOIN
database2.documents as Document ON Document.user_id = User.id
3. But Cake doesn't put in the database prefixes - as in Cake the
only way to get two databases is with two database connections, and it
is not assumed that these will have the same access details (fair
enough).
4. If you are sure that this kind of query will work, you can
construct it manually. Or, you can do something tricky like:
// add this to your /app/app_model.php
function getDatabaseName()
{
$conn =& ConnectionManager::getInstance();
$db_name = $conn->config->{$this->useDbConfig}['database'];
return $db_name;
}
// make your query like:
// first add the database names to the model's table prefix
$this->Document->tablePrefix = $this->Document->getDatabaseName() .'.'.
$this->Document->tablePrefix;
$this->Document->User->tablePrefix = $this->Document->User-
>getDatabaseName() .'.'.$this->Document->User->tablePrefix;
// now make the query
$this->Document->recursive = 1;
$this->Document->findAll(array('User.id'=>'1'));
I'm not 100% sure that the above will work as is - but I have
something similar in a modified version of
http://bakery.cakephp.org/articles/view/extending-of-dbosource-and-model-with-sql-generator-function
and it works fine to create queries joining across databases.
--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---