Link 2 个带有 PDO 的 Firebird 数据库

Link 2 Firebird databases with PDO

简短摘要。我有 2 个数据库(Invoices.gdb 和 Users.gdb) 我想获得一个 table,我可以在其中查看哪个发票链接到哪个客户 供您参考:我知道 PHP 代码可以将我的值输入 table。我正在努力让我的 LINK 介于 2 个数据库之间,以及如何执行此查询。

我的 PDO class(现在只包含 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;
    }

这只是为了吸引我的用户(并且有效)。如何添加我的发票数据库?

这是我的 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;
    }

我要进行的查询如下:

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

我无法将这两个数据库合并在一起。所以这不是解决方案。 提前致谢!

Firebird 数据库是孤立的,您不能在数据库之间加入。最好的解决方案是将您的两个数据库合并为一个(这还具有进行完整性检查(如外键约束等)的额外好处)。

第二个最好的办法是在您的 发票 数据库。然后,您需要将 users 中的更改同步到 invoices(例如,使用触发器和 EXECUTE STATEMENT ON EXTERNAL,或计划作业来执行同步)。

否则您将不得不在代码中手动加入,这远非最佳。