How to use multiple database adapter to query involving tables from different databases?

Posted by understack on Stack Overflow See other posts from Stack Overflow or by understack
Published on 2010-04-23T19:03:12Z Indexed on 2010/04/23 19:13 UTC
Read the original article Hit count: 209

Filed under:
|
|
|

I've 2 databases, which are set up as mentioned here. How can I write a SQL query which involves database_1.table_1 and database_2.table_1 ?

E.g. consider this query

$sql = "SELECT distinct database_1.users.id, database_1.users.name
        FROM database_1.users, database_2.sales
        WHERE database_2.sales.user_id = database_1.users.id";

How this query could be written using multiple db adapter?

Edit

I'm using 2 databases, because this way I can change actual database names in application.ini. Is there any other way I can change database names without changing sql queries?

© Stack Overflow or respective owner

Related posts about php

Related posts about sql