php-di

How to set up and inject multiple PDO database connections in slim 4?

我与影子孤独终老i 提交于 2020-01-24 09:39:24
问题 I could make an instance of PDO and inject it successfully. I defined the PDO::class directly and injected it in the constructor with __construct(PDO $pdo) . I would need something like PDO1::class and PDO2::class to inject it like follows: __construct(PDO1 $pdo1, PDO2 $pdo2) but that obviously doesn't work. There is only one PDO class and what I need to do is 2 instances of it with different database credentials. What is the best way to do it? I set up one definition of a database via PDO

How to set up and inject multiple PDO database connections in slim 4?

折月煮酒 提交于 2020-01-24 09:37:06
问题 I could make an instance of PDO and inject it successfully. I defined the PDO::class directly and injected it in the constructor with __construct(PDO $pdo) . I would need something like PDO1::class and PDO2::class to inject it like follows: __construct(PDO1 $pdo1, PDO2 $pdo2) but that obviously doesn't work. There is only one PDO class and what I need to do is 2 instances of it with different database credentials. What is the best way to do it? I set up one definition of a database via PDO

How do I fetch the PHP DI container?

十年热恋 提交于 2019-12-13 10:30:05
问题 How do I load a database container using PHP DI? This is one of the variations I have tried up until now. Settings.php <?php use MyApp\Core\Database; use MyApp\Models\SystemUser; return [ 'Database' => new Database(), 'SystemUser' => new SystemUser() ]; init.php $containerBuilder = new \DI\ContainerBuilder(); $containerBuilder->addDefinitions('Settings.php'); $container = $containerBuilder->build(); SystemUserDetails.php <?php namespace MyApp\Models\SystemUser; use MyApp\Core\Database; use