From ad04716fdc5ad507948c70f18830a537715a7bda Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 22 Jan 2016 22:51:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=98=E9=87=8F=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Driver.php | 38 +++++++++++++++--------------- library/think/db/driver/Mongo.php | 16 ++++++------- library/think/db/driver/Oracle.php | 6 ++--- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/library/think/db/Driver.php b/library/think/db/Driver.php index 3aa94307..5b56b6fe 100644 --- a/library/think/db/Driver.php +++ b/library/think/db/Driver.php @@ -36,9 +36,9 @@ abstract class Driver // 错误信息 protected $error = ''; // 数据库连接ID 支持多个连接 - protected $linkID = []; + protected $links = []; // 当前连接ID - protected $_linkID = null; + protected $linkID = null; // 数据库连接参数配置 protected $config = [ // 数据库类型 @@ -111,7 +111,7 @@ abstract class Driver */ public function connect($config = '', $linkNum = 0, $autoConnection = false) { - if (!isset($this->linkID[$linkNum])) { + if (!isset($this->links[$linkNum])) { if (empty($config)) { $config = $this->config; } @@ -120,7 +120,7 @@ abstract class Driver if (empty($config['dsn'])) { $config['dsn'] = $this->parseDsn($config); } - $this->linkID[$linkNum] = new PDO($config['dsn'], $config['username'], $config['password'], $this->options); + $this->links[$linkNum] = new PDO($config['dsn'], $config['username'], $config['password'], $this->options); } catch (\PDOException $e) { if ($autoConnection) { Log::record($e->getMessage(), 'error'); @@ -130,7 +130,7 @@ abstract class Driver } } } - return $this->linkID[$linkNum]; + return $this->links[$linkNum]; } /** @@ -163,7 +163,7 @@ abstract class Driver public function query($sql, $bind = [], $fetch = false, $master = false) { $this->initConnect($master); - if (!$this->_linkID) { + if (!$this->linkID) { return false; } @@ -185,7 +185,7 @@ abstract class Driver // 调试开始 $this->debug(true); // 预处理 - $this->PDOStatement = $this->_linkID->prepare($sql); + $this->PDOStatement = $this->linkID->prepare($sql); // 参数绑定 $this->bindValue($bind); // 执行查询 @@ -209,7 +209,7 @@ abstract class Driver public function execute($sql, $bind = [], $fetch = false) { $this->initConnect(true); - if (!$this->_linkID) { + if (!$this->linkID) { return false; } @@ -231,7 +231,7 @@ abstract class Driver // 调试开始 $this->debug(true); // 预处理 - $this->PDOStatement = $this->_linkID->prepare($sql); + $this->PDOStatement = $this->linkID->prepare($sql); // 参数绑定操作 $this->bindValue($bind); // 执行语句 @@ -241,7 +241,7 @@ abstract class Driver $this->numRows = $this->PDOStatement->rowCount(); if (preg_match("/^\s*(INSERT\s+INTO|REPLACE\s+INTO)\s+/i", $sql)) { - $this->lastInsID = $this->_linkID->lastInsertId(); + $this->lastInsID = $this->linkID->lastInsertId(); } return $this->numRows; } catch (\PDOException $e) { @@ -281,13 +281,13 @@ abstract class Driver public function startTrans() { $this->initConnect(true); - if (!$this->_linkID) { + if (!$this->linkID) { return false; } //数据rollback 支持 if (0 == $this->transTimes) { - $this->_linkID->beginTransaction(); + $this->linkID->beginTransaction(); } $this->transTimes++; return; @@ -302,7 +302,7 @@ abstract class Driver { if ($this->transTimes > 0) { try { - $result = $this->_linkID->commit(); + $result = $this->linkID->commit(); $this->transTimes = 0; } catch (\PDOException $e) { throw new Exception($e->getMessage()); @@ -320,7 +320,7 @@ abstract class Driver { if ($this->transTimes > 0) { try { - $result = $this->_linkID->rollback(); + $result = $this->linkID->rollback(); $this->transTimes = 0; } catch (\PDOException $e) { throw new Exception($e->getMessage()); @@ -369,7 +369,7 @@ abstract class Driver */ public function close() { - $this->_linkID = null; + $this->linkID = null; } /** @@ -1124,7 +1124,7 @@ abstract class Driver public function quote($str) { $this->initConnect(); - return $this->_linkID ? $this->_linkID->quote($str) : $str; + return $this->linkID ? $this->linkID->quote($str) : $str; } /** @@ -1168,10 +1168,10 @@ abstract class Driver { if (!empty($this->config['deploy'])) { // 采用分布式数据库 - $this->_linkID = $this->multiConnect($master); - } elseif (!$this->_linkID) { + $this->linkID = $this->multiConnect($master); + } elseif (!$this->linkID) { // 默认单数据库 - $this->_linkID = $this->connect(); + $this->linkID = $this->connect(); } } diff --git a/library/think/db/driver/Mongo.php b/library/think/db/driver/Mongo.php index 75897767..5ecf28bb 100644 --- a/library/think/db/driver/Mongo.php +++ b/library/think/db/driver/Mongo.php @@ -61,19 +61,19 @@ class Mongo extends Driver */ public function connect($config = '', $linkNum = 0, $autoConnection = false) { - if (!isset($this->linkID[$linkNum])) { + if (!isset($this->links[$linkNum])) { if (empty($config)) { $config = $this->config; } $host = 'mongodb://' . ($config['username'] ? "{$config['username']}" : '') . ($config['password'] ? ":{$config['password']}@" : '') . $config['hostname'] . ($config['hostport'] ? ":{$config['hostport']}" : '') . '/' . ($config['database'] ? "{$config['database']}" : ''); try { - $this->linkID[$linkNum] = new \mongoClient($host, !empty($this->config['params']) ? $this->config['params'] : array()); + $this->links[$linkNum] = new \mongoClient($host, !empty($this->config['params']) ? $this->config['params'] : array()); } catch (\MongoConnectionException $e) { throw new Exception($e->getmessage()); } } - return $this->linkID[$linkNum]; + return $this->links[$linkNum]; } /** @@ -89,7 +89,7 @@ class Mongo extends Driver public function switchCollection($collection, $db = '', $master = true) { // 当前没有连接 则首先进行数据库连接 - if (!$this->_linkID) { + if (!$this->linkID) { $this->initConnect($master); } @@ -100,7 +100,7 @@ class Mongo extends Driver // 传人Db则切换数据库 // 当前MongoDb对象 $this->_dbName = $db; - $this->_mongo = $this->_linkID->selectDb($db); + $this->_mongo = $this->linkID->selectDb($db); } // 当前MongoCollection对象 if ($this->config['debug']) { @@ -176,9 +176,9 @@ class Mongo extends Driver */ public function close() { - if ($this->_linkID) { - $this->_linkID->close(); - $this->_linkID = null; + if ($this->linkID) { + $this->linkID->close(); + $this->linkID = null; $this->_mongo = null; $this->_collection = null; $this->_cursor = null; diff --git a/library/think/db/driver/Oracle.php b/library/think/db/driver/Oracle.php index 5ab0f083..dccb815c 100644 --- a/library/think/db/driver/Oracle.php +++ b/library/think/db/driver/Oracle.php @@ -47,7 +47,7 @@ class Oracle extends Driver public function execute($str, $bind = []) { $this->initConnect(true); - if (!$this->_linkID) { + if (!$this->linkID) { return false; } @@ -69,12 +69,12 @@ class Oracle extends Driver try { // 记录开始执行时间 $this->debug(true); - $this->PDOStatement = $this->_linkID->prepare($str); + $this->PDOStatement = $this->linkID->prepare($str); $result = $this->PDOStatement->execute($bind); $this->debug(false); $this->numRows = $this->PDOStatement->rowCount(); if ($flag || preg_match("/^\s*(INSERT\s+INTO|REPLACE\s+INTO)\s+/i", $str)) { - $this->lastInsID = $this->_linkID->lastInsertId(); + $this->lastInsID = $this->linkID->lastInsertId(); } return $this->numRows; } catch (\PDOException $e) {