/** * 初始化DB句柄 * * @return void * @throws WindDbException */ public function init() { try { if ($this->_dbHandle !== null) { return; } $driverName = $this->getDriverName(); $dbHandleClass = "WIND:db." . $driverName . ".Wind" . ucfirst($driverName) . "PdoAdapter"; $dbHandleClass = Wind::import($dbHandleClass); $this->_dbHandle = new $dbHandleClass($this->_dsn, $this->_user, $this->_pwd, (array) $this->_attributes); $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); $this->_dbHandle->setCharset($this->_charset); } catch (PDOException $e) { $this->close(); throw new WindDbException('[db.WindConnection.init] ' . $e->getMessage()); } }
/** * 初始化DB句柄 * * @return void * @throws WindDbException */ public function init() { try { if ($this->_dbHandle !== null) { return; } $driverName = $this->getDriverName(); $dbHandleClass = "WIND:db." . $driverName . ".Wind" . ucfirst($driverName) . "PdoAdapter"; $dbHandleClass = Wind::import($dbHandleClass); $this->_dbHandle = new $dbHandleClass($this->_dsn, $this->_user, $this->_pwd, (array) $this->_attributes); $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->_dbHandle->setCharset($this->_charset); if (WIND_DEBUG & 2) { Wind::getApp()->getComponent('windLogger')->info("[db.WindConnection.init] Initialize db connection success. \r\n\tDSN:" . $this->_dsn . "\r\n\tUser:"******"\r\n\tCharset:" . $this->_charset . "\r\n\tTablePrefix:" . $this->_tablePrefix . "\r\n\tDriverName:" . $this->_driverName, 'db'); } } catch (PDOException $e) { $this->close(); throw new WindDbException($e->getMessage()); } }