簡體   English   中英

使用POG的多個數據庫連接

[英]Multiple database connections with POG

我一直在使用POG(PHP對象生成- http://www.phpobjectgenerator.com/ )的一個項目,我需要做的多個數據庫連接。

在配置文件中,我僅定義一個連接。

如何使用POG連接到多個數據庫?

謝謝

我在幾個項目中使用pog。 有時我會在同一腳本執行期間更改數據庫連接。 為此,我向數據庫類添加了一個名為Reset的新方法,並重寫了Connect方法。 類看起來像這樣:

public class Database{
    //..
    static $database = null;
    public static function Connect()
    {
        if (!isset(self::$database) || is_null(self::$database))
        {
            self::$database = new Database();
        }
        return self::$database->connection;
    }

    public static function Reset()
    {
        mysql_close(self::$database->connection);
        unset(self::$database);
    }
}

//用法:

include('configuration.php');
// use pog with first database
Database::Reset();
include('other_configuration.php');
// use pog with another database

您也可以考慮將問題發送到php-object-generator@googlegroups.com

祝你今天愉快

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM