Nefunkcni pripojeni k vice DB najednou
- Rafe
- Člen | 9
Ahoj,
prosel jsem snad vsechny topicy na toto tema na foru, nicmene stale nejsem s to rozjet pripojeni k vice MySQL db, hadam ze delam chybu v nejakem zakladu pouzivani DI, ale nemuzu prijit na to co je spatne :/
config.neon
...
database:
default:
dsn: 'mysql:host=localhost;dbname=xxx'
user: xxx
password: xxx
options:
lazy: true
autowired: true
db_ekd:
dsn: 'mysql:host=xxx;dbname=xxx'
user: xxx
password: xxx
options:
lazy: true
autowired: false
services:
dbEKD: Factories\DatabaseFactory(@nette.database.db_ekd.context)
...
DatabaseFactory:
<?php
use Nette\Database\Context;
class DatabaseFactory
{
/** @var Context */
private $database;
/**
* DatabaseFactory constructor.
* @param Context $database
*/
public function __construct(Context $database)
{
$this->database = $database;
}
/**
* @return Context
*/
public function getDatabase() {
return $this->database;
}
}
?>
V presenteru se k tomu dostanu skrze:
<?php
/**
* @var DatabaseFactory
* @inject
*/
private $dbEKD;
?>
Nicmene pokud si v presenteru zkusim:
<?php
public function renderDefault()
{
print_r($this->dbEKD->getDatabase());
}
?>
Dostavam z toho pouze null. Pokud lezu do dane databaze primo pres exec(‚mysql …‘) tak se k DB dostanu, predpokladam tedy ze nastavenim serveru to nebude.
Editoval Rafe (6. 2. 2018 13:15)