vendredi 17 juin 2016

PHP using multiple MySQL database connections

I'm creating an application that makes use of 3 different databases on different servers. Fetching data happens in my Data mappers, each extending an abstract DataMapper parent class:

abstract class DataMapper {

    protected $db;
    protected $db2;
    protected $db3;

    function __construct() {
        $this->db = new Database('db1');
        $this->db2 = new Database('db2');
        $this->db3 = new Database('db3');
    }

}

However, this would be a little overkill for pages that only requires on of these 3 connections. What would be the best way to return the correct Database connection for every part of the application? I've heard about Application Registries, but I have no idea how to set up something like that.

Aucun commentaire:

Enregistrer un commentaire