Authored by 沈海生

添加提示

@@ -143,11 +143,11 @@ class PDOConnection extends Root @@ -143,11 +143,11 @@ class PDOConnection extends Root
143 $_serverConfig = $server->getServerConfig('database', $this->_database); 143 $_serverConfig = $server->getServerConfig('database', $this->_database);
144 $_dbConfig = $server->getServerConfig('mysql'); 144 $_dbConfig = $server->getServerConfig('mysql');
145 if (!isset($_serverConfig[$modality]) || !in_array($modality, array('write', 'read'))) { 145 if (!isset($_serverConfig[$modality]) || !in_array($modality, array('write', 'read'))) {
146 - throw new DebugException('MySQL Not Modality ' . $modality); 146 + throw new DebugException('MySQL db:'.$this->_database.' Not Modality ' . $modality);
147 } 147 }
148 $_server = $server->getServerMap($_serverConfig[$modality], Server::SERVER_SELECT_MODEL_RAND); 148 $_server = $server->getServerMap($_serverConfig[$modality], Server::SERVER_SELECT_MODEL_RAND);
149 if (empty($_server)) { 149 if (empty($_server)) {
150 - throw new DebugException('Db Server is null.'); 150 + throw new DebugException('Db:'.$this->_database.' Server is null.');
151 } 151 }
152 $charset = isset($_dbConfig['charset']) ? $_dbConfig['charset'] : 'UTF8'; 152 $charset = isset($_dbConfig['charset']) ? $_dbConfig['charset'] : 'UTF8';
153 #如果设置了 dbname 使用 配置的 153 #如果设置了 dbname 使用 配置的
@@ -158,7 +158,12 @@ class PDOConnection extends Root @@ -158,7 +158,12 @@ class PDOConnection extends Root
158 \PDO::ATTR_PERSISTENT => isset($_dbConfig['persistent']) ? $_dbConfig['persistent'] : false, 158 \PDO::ATTR_PERSISTENT => isset($_dbConfig['persistent']) ? $_dbConfig['persistent'] : false,
159 \PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES " . $charset 159 \PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES " . $charset
160 ); 160 );
161 - $_connection = new \PDO($dsn, $_serverConfig['username'], $_serverConfig['passwd'], $options); 161 + try {
  162 + $_connection = new \PDO($dsn, $_serverConfig['username'], $_serverConfig['passwd'], $options);
  163 + } catch (\Exception $e) {
  164 + throw new DebugException($dsn . ' error ' . $e->getMessage());
  165 + }
  166 +
162 foreach ($this->_attribute as $key => $val) { 167 foreach ($this->_attribute as $key => $val) {
163 $_connection->setAttribute($key, $val); 168 $_connection->setAttribute($key, $val);
164 } 169 }