简体   繁体   English

将 2 个 Firebird 数据库与 PDO 连接起来

[英]Link 2 Firebird databases with PDO

Short summary.简短的摘要。 I have 2 databases (Invoices.gdb and Users.gdb) I want to get a table where I can see which Invoice is linked to wich customer For you info: I know the PHP code to get my values into the table.我有 2 个数据库(Invoices.gdb 和 Users.gdb)我想得到一个表,在那里我可以看到哪个 Invoice 链接到哪个客户 给你的信息:我知道将我的值放入表中的 PHP 代码。 I'm struggling to get my LINK right between the 2 databases AND how I can execute this query.我正在努力在 2 个数据库之间建立我的 LINK 以及如何执行此查询。

My PDO class (only contains 1 connection right now)我的 PDO 类(现在只包含 1 个连接)

class DatabasePDO{
    /** @var PDO */
    private static $dbh;

    static function getInstance(){
        $str_conn="firebird:host=localhost;dbname=C:/Users/Desktop/USERS.GDB;charset=UTF8";
        try{
            self::$dbh = new PDO($str_conn, "username", "password");
        }
        catch(PDOException $e){
            echo "Error!: ".$e->getMessage();
            die();
        }
        return self::$dbh;
    }

That's only to get my users(and it works).那只是为了让我的用户(并且它有效)。 How can I add my Invoices DB?如何添加我的发票数据库?

This is my class这是我的课

public static function getInvoices() {
        $conn = DatabasePDO::getInstance();
        $sql = "select * from users.customers as A , invoices.invoice as B
                where a.customers.customerid = b.invoice.customerid";
        $st = $conn->prepare($sql);
        $st->execute();
        $list = array();
        while ( $row = $st->fetch() ) {
            $invoice= new invoice( $row );
            $list[] = $invoice;
        }
        $conn = null;
        return $list;
    }

The query I want to make is this the following:我想做的查询如下:

select * from users.customers as A , invoices.invoice as B
where a.customers.customerid = b.invoice.customerid

I can't merge the 2 databases together.我无法将 2 个数据库合并在一起。 So that's no solution.所以这不是解决方案。 Thanks in advance!提前致谢!

Firebird databases are isolated and you can't join between databases. Firebird 数据库是隔离的,您无法在数据库之间加入。 The best solution would be to merge your two databases into one (that would also have the added benefit of having integrity checks like foreign key constraints, etc).最好的解决方案是将您的两个数据库合并为一个(这还具有进行完整性检查(如外键约束等)的额外好处)。

The second best would be to have a copy of your users database (or at least the required tables) in your invoices database.第二个最好的方法是在您的发票数据库中有一份您的用户数据库(或至少是所需的表)的副本 You would then need to synchronize changes in users to invoices (eg using triggers and EXECUTE STATEMENT ON EXTERNAL , or a scheduled to job to do the synchronization).然后,您需要将用户中的更改同步到发票(例如,使用触发器和EXECUTE STATEMENT ON EXTERNAL或计划执行同步的作业)。

Otherwise you will have to do joining by hand in your code, and this is far from optimal.否则,您将不得不在代码中手动加入,这远非最佳。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM