doudoulb1234 2010-04-23 19:03
浏览 78
已采纳

如何使用多个数据库适配器来查询涉及不同数据库的表?

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 thought of using 2 database adapters 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?

Solution I'm using: I used another config variable to read second database name. First database name comes from adapter settings.

  • 写回答

1条回答 默认 最新

  • dongque1462 2010-04-23 19:06
    关注

    You can't unless you use something like Federated databases, but even then you'd use one database adapter for the query and let the database handle the fetching from the federated other databases.

    Zend_Application_Resource_Multidb is just setting up multiple database adapters at once. Nothing more. You will use each adapter separately from the other. Use Adapter1 to query database1 and use adapter to query database2. Two queries. Merge the results inside your application.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False