|
@@ -16,8 +16,9 @@ class Connection extends ConnBase implements ConnIntf
|
|
{
|
|
{
|
|
const VERSION = '1.2';
|
|
const VERSION = '1.2';
|
|
|
|
|
|
- public function __construct()
|
|
|
|
|
|
+ public function __construct($dbInfo = array())
|
|
{
|
|
{
|
|
|
|
+ Register::mergeAppConfigure(Register::getAppConfigure(Consts::APP_DB), $dbInfo);
|
|
$this->_dbInfo = Register::getAppConfigure(Register::get(Consts::APP_DB));
|
|
$this->_dbInfo = Register::getAppConfigure(Register::get(Consts::APP_DB));
|
|
if(!isset($this->_dbInfo['use_db_driver'])) $this->_dbInfo['use_db_driver'] = 'mysql';
|
|
if(!isset($this->_dbInfo['use_db_driver'])) $this->_dbInfo['use_db_driver'] = 'mysql';
|
|
}
|
|
}
|
|
@@ -28,10 +29,10 @@ class Connection extends ConnBase implements ConnIntf
|
|
*/
|
|
*/
|
|
public function getReadConnection()
|
|
public function getReadConnection()
|
|
{
|
|
{
|
|
- if (self::$_readConnection != null) {
|
|
|
|
- return self::$_readConnection;
|
|
|
|
- }
|
|
|
|
list($dbInfo, $useSlave) = $this->getDBInfoAndSalve();
|
|
list($dbInfo, $useSlave) = $this->getDBInfoAndSalve();
|
|
|
|
+ if (self::$_readConnection[$dbInfo['db']] != null) {
|
|
|
|
+ return self::$_readConnection[$dbInfo['db']];
|
|
|
|
+ }
|
|
if ($useSlave) {
|
|
if ($useSlave) {
|
|
try {
|
|
try {
|
|
if ($this->_dbInfo['use_db_driver'] == 'mssql') {
|
|
if ($this->_dbInfo['use_db_driver'] == 'mssql') {
|
|
@@ -39,8 +40,7 @@ class Connection extends ConnBase implements ConnIntf
|
|
} else {
|
|
} else {
|
|
$dsn = $this->_dbInfo['use_db_driver'] . ":host=" . $dbInfo['host'] . ";dbname=" . $dbInfo['db'];
|
|
$dsn = $this->_dbInfo['use_db_driver'] . ":host=" . $dbInfo['host'] . ";dbname=" . $dbInfo['db'];
|
|
}
|
|
}
|
|
- self::$_readConnection = new \PDO($dsn, $dbInfo['user'], $dbInfo['password']);
|
|
|
|
- return self::$_readConnection;
|
|
|
|
|
|
+ return self::$_readConnection[$dbInfo['db']] = new \PDO($dsn, $dbInfo['user'], $dbInfo['password']);
|
|
} catch (Exception $e) {
|
|
} catch (Exception $e) {
|
|
return $this->getWriteConnection();
|
|
return $this->getWriteConnection();
|
|
}
|
|
}
|
|
@@ -54,17 +54,17 @@ class Connection extends ConnBase implements ConnIntf
|
|
*/
|
|
*/
|
|
public function getWriteConnection()
|
|
public function getWriteConnection()
|
|
{
|
|
{
|
|
- if (self::$_writeConnection != null) {
|
|
|
|
- return self::$_writeConnection;
|
|
|
|
|
|
+ $dbInfo = $this->_dbInfo['master'];
|
|
|
|
+ if (self::$_writeConnection[$dbInfo['db']] != null) {
|
|
|
|
+ return self::$_writeConnection[$dbInfo['db']];
|
|
}
|
|
}
|
|
- $dbInfo = $this->_dbInfo['master'];
|
|
|
|
try {
|
|
try {
|
|
if ($this->_dbInfo['use_db_driver'] == 'mssql') {
|
|
if ($this->_dbInfo['use_db_driver'] == 'mssql') {
|
|
$dsn = 'odbc:Driver={SQL Server};Server=' . $dbInfo['host'] . ';Database=' . $dbInfo['db'] . ';';
|
|
$dsn = 'odbc:Driver={SQL Server};Server=' . $dbInfo['host'] . ';Database=' . $dbInfo['db'] . ';';
|
|
} else {
|
|
} else {
|
|
$dsn = $this->_dbInfo['use_db_driver'] . ":host=" . $dbInfo['host'] . ";dbname=" . $dbInfo['db'];
|
|
$dsn = $this->_dbInfo['use_db_driver'] . ":host=" . $dbInfo['host'] . ";dbname=" . $dbInfo['db'];
|
|
}
|
|
}
|
|
- return self::$_writeConnection = new \PDO($dsn, $dbInfo['user'], $dbInfo['password']);
|
|
|
|
|
|
+ return self::$_writeConnection[$dbInfo['db']] = new \PDO($dsn, $dbInfo['user'], $dbInfo['password']);
|
|
} catch (Exception $e) {
|
|
} catch (Exception $e) {
|
|
throw new Errors(\Qii::i(1500, $dbInfo['host'], $dbInfo['user'], $dbInfo['password'], $dbInfo['db'], toUTF8($e->getMessage())), __LINE__);
|
|
throw new Errors(\Qii::i(1500, $dbInfo['host'], $dbInfo['user'], $dbInfo['password'], $dbInfo['db'], toUTF8($e->getMessage())), __LINE__);
|
|
}
|
|
}
|