且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使php代码使用两个不同的主机连接到两个不同的数据库?

更新时间:2022-12-31 15:14:56

只需创建2个数据库类实例。

公共静态函数getInstance(){} $ c $的删除c>
不要这样:

Rid of, public static function getInstance(){} Dont do like this:

$db = Database::getInstance();

相反:

$db1 = new Database();
$db2 = new Database();

数据库构造函数编辑为类似

public function __construct($dns, $username, $password){
    $this->db = new PDO($dns,$username,$password);
}