Dsn.php
1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/**
* Created by PhpStorm.
* User: Zip
* Date: 15/12/22
* Time: 18:32
*/
namespace Hood\Dao\Db\PostgreSQL;
use Hood\Core\Root;
use Hood\Core\Server;
class Dsn extends Root
{
/**
* 获取DB配置
* @param $dbname
* @return array
* @throws Exception
*/
public function getConfig($dbname, $proxy = null)
{
$server = $this->getServerHost('db');
$node = $dbname;
if ($proxy != null) {
$node = $proxy;
}
$_serverConfig = $server->getServerConfig('postgre.database', $node);
if (empty($_serverConfig)) {
throw new \Exception('db.' . APPLICATION_ENV . '.config.ini No [postgre.database] Node.');
}
$_dbConfig = $server->getServerConfig('mysql');
$_server = $server->getServerMap($_serverConfig['write'], Server::SERVER_SELECT_MODEL_RAND);
if (empty($_server)) {
throw new \Exception('Db:' . $dbname . ' Server is null.');
}
$dbname = isset($_serverConfig['dbname']) ? $_serverConfig['dbname'] : $dbname;
$_dbConfig['dbname'] = $dbname;
return array_merge($_dbConfig, $_serverConfig);
}
}