Hey everbody,
I'm developing a Rest application with a micro setup plus collections to structure the logic. In every Rest Uri I get the database plus the id or whatever is needed for the function. Example:
GET /api/search/exampleModel/id+exampleDB
How should I handle the connection to the diffrent databases?
Idea:
1 Set the dbs:
$di->set('dbExample', function(){ return new PdoMysql(array( "host" => "localhost", "username" => "", "password" => "", "dbname" => "" )); });
2 Create function in model:
public function changeDb($db) { $this->setConnectionService($db); }
3 Create object of the model inside the controller and change db:
$myModell = new ExampleModell(); $myModell->changeDb("dbExample");
Is there a better way to handle this situation?
Bruno