mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-08 07:32:48 +08:00
变量规范
This commit is contained in:
@@ -36,9 +36,9 @@ abstract class Driver
|
|||||||
// 错误信息
|
// 错误信息
|
||||||
protected $error = '';
|
protected $error = '';
|
||||||
// 数据库连接ID 支持多个连接
|
// 数据库连接ID 支持多个连接
|
||||||
protected $linkID = [];
|
protected $links = [];
|
||||||
// 当前连接ID
|
// 当前连接ID
|
||||||
protected $_linkID = null;
|
protected $linkID = null;
|
||||||
// 数据库连接参数配置
|
// 数据库连接参数配置
|
||||||
protected $config = [
|
protected $config = [
|
||||||
// 数据库类型
|
// 数据库类型
|
||||||
@@ -111,7 +111,7 @@ abstract class Driver
|
|||||||
*/
|
*/
|
||||||
public function connect($config = '', $linkNum = 0, $autoConnection = false)
|
public function connect($config = '', $linkNum = 0, $autoConnection = false)
|
||||||
{
|
{
|
||||||
if (!isset($this->linkID[$linkNum])) {
|
if (!isset($this->links[$linkNum])) {
|
||||||
if (empty($config)) {
|
if (empty($config)) {
|
||||||
$config = $this->config;
|
$config = $this->config;
|
||||||
}
|
}
|
||||||
@@ -120,7 +120,7 @@ abstract class Driver
|
|||||||
if (empty($config['dsn'])) {
|
if (empty($config['dsn'])) {
|
||||||
$config['dsn'] = $this->parseDsn($config);
|
$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) {
|
} catch (\PDOException $e) {
|
||||||
if ($autoConnection) {
|
if ($autoConnection) {
|
||||||
Log::record($e->getMessage(), 'error');
|
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)
|
public function query($sql, $bind = [], $fetch = false, $master = false)
|
||||||
{
|
{
|
||||||
$this->initConnect($master);
|
$this->initConnect($master);
|
||||||
if (!$this->_linkID) {
|
if (!$this->linkID) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,7 +185,7 @@ abstract class Driver
|
|||||||
// 调试开始
|
// 调试开始
|
||||||
$this->debug(true);
|
$this->debug(true);
|
||||||
// 预处理
|
// 预处理
|
||||||
$this->PDOStatement = $this->_linkID->prepare($sql);
|
$this->PDOStatement = $this->linkID->prepare($sql);
|
||||||
// 参数绑定
|
// 参数绑定
|
||||||
$this->bindValue($bind);
|
$this->bindValue($bind);
|
||||||
// 执行查询
|
// 执行查询
|
||||||
@@ -209,7 +209,7 @@ abstract class Driver
|
|||||||
public function execute($sql, $bind = [], $fetch = false)
|
public function execute($sql, $bind = [], $fetch = false)
|
||||||
{
|
{
|
||||||
$this->initConnect(true);
|
$this->initConnect(true);
|
||||||
if (!$this->_linkID) {
|
if (!$this->linkID) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,7 +231,7 @@ abstract class Driver
|
|||||||
// 调试开始
|
// 调试开始
|
||||||
$this->debug(true);
|
$this->debug(true);
|
||||||
// 预处理
|
// 预处理
|
||||||
$this->PDOStatement = $this->_linkID->prepare($sql);
|
$this->PDOStatement = $this->linkID->prepare($sql);
|
||||||
// 参数绑定操作
|
// 参数绑定操作
|
||||||
$this->bindValue($bind);
|
$this->bindValue($bind);
|
||||||
// 执行语句
|
// 执行语句
|
||||||
@@ -241,7 +241,7 @@ abstract class Driver
|
|||||||
|
|
||||||
$this->numRows = $this->PDOStatement->rowCount();
|
$this->numRows = $this->PDOStatement->rowCount();
|
||||||
if (preg_match("/^\s*(INSERT\s+INTO|REPLACE\s+INTO)\s+/i", $sql)) {
|
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;
|
return $this->numRows;
|
||||||
} catch (\PDOException $e) {
|
} catch (\PDOException $e) {
|
||||||
@@ -281,13 +281,13 @@ abstract class Driver
|
|||||||
public function startTrans()
|
public function startTrans()
|
||||||
{
|
{
|
||||||
$this->initConnect(true);
|
$this->initConnect(true);
|
||||||
if (!$this->_linkID) {
|
if (!$this->linkID) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//数据rollback 支持
|
//数据rollback 支持
|
||||||
if (0 == $this->transTimes) {
|
if (0 == $this->transTimes) {
|
||||||
$this->_linkID->beginTransaction();
|
$this->linkID->beginTransaction();
|
||||||
}
|
}
|
||||||
$this->transTimes++;
|
$this->transTimes++;
|
||||||
return;
|
return;
|
||||||
@@ -302,7 +302,7 @@ abstract class Driver
|
|||||||
{
|
{
|
||||||
if ($this->transTimes > 0) {
|
if ($this->transTimes > 0) {
|
||||||
try {
|
try {
|
||||||
$result = $this->_linkID->commit();
|
$result = $this->linkID->commit();
|
||||||
$this->transTimes = 0;
|
$this->transTimes = 0;
|
||||||
} catch (\PDOException $e) {
|
} catch (\PDOException $e) {
|
||||||
throw new Exception($e->getMessage());
|
throw new Exception($e->getMessage());
|
||||||
@@ -320,7 +320,7 @@ abstract class Driver
|
|||||||
{
|
{
|
||||||
if ($this->transTimes > 0) {
|
if ($this->transTimes > 0) {
|
||||||
try {
|
try {
|
||||||
$result = $this->_linkID->rollback();
|
$result = $this->linkID->rollback();
|
||||||
$this->transTimes = 0;
|
$this->transTimes = 0;
|
||||||
} catch (\PDOException $e) {
|
} catch (\PDOException $e) {
|
||||||
throw new Exception($e->getMessage());
|
throw new Exception($e->getMessage());
|
||||||
@@ -369,7 +369,7 @@ abstract class Driver
|
|||||||
*/
|
*/
|
||||||
public function close()
|
public function close()
|
||||||
{
|
{
|
||||||
$this->_linkID = null;
|
$this->linkID = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1124,7 +1124,7 @@ abstract class Driver
|
|||||||
public function quote($str)
|
public function quote($str)
|
||||||
{
|
{
|
||||||
$this->initConnect();
|
$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'])) {
|
if (!empty($this->config['deploy'])) {
|
||||||
// 采用分布式数据库
|
// 采用分布式数据库
|
||||||
$this->_linkID = $this->multiConnect($master);
|
$this->linkID = $this->multiConnect($master);
|
||||||
} elseif (!$this->_linkID) {
|
} elseif (!$this->linkID) {
|
||||||
// 默认单数据库
|
// 默认单数据库
|
||||||
$this->_linkID = $this->connect();
|
$this->linkID = $this->connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,19 +61,19 @@ class Mongo extends Driver
|
|||||||
*/
|
*/
|
||||||
public function connect($config = '', $linkNum = 0, $autoConnection = false)
|
public function connect($config = '', $linkNum = 0, $autoConnection = false)
|
||||||
{
|
{
|
||||||
if (!isset($this->linkID[$linkNum])) {
|
if (!isset($this->links[$linkNum])) {
|
||||||
if (empty($config)) {
|
if (empty($config)) {
|
||||||
$config = $this->config;
|
$config = $this->config;
|
||||||
}
|
}
|
||||||
|
|
||||||
$host = 'mongodb://' . ($config['username'] ? "{$config['username']}" : '') . ($config['password'] ? ":{$config['password']}@" : '') . $config['hostname'] . ($config['hostport'] ? ":{$config['hostport']}" : '') . '/' . ($config['database'] ? "{$config['database']}" : '');
|
$host = 'mongodb://' . ($config['username'] ? "{$config['username']}" : '') . ($config['password'] ? ":{$config['password']}@" : '') . $config['hostname'] . ($config['hostport'] ? ":{$config['hostport']}" : '') . '/' . ($config['database'] ? "{$config['database']}" : '');
|
||||||
try {
|
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) {
|
} catch (\MongoConnectionException $e) {
|
||||||
throw new Exception($e->getmessage());
|
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)
|
public function switchCollection($collection, $db = '', $master = true)
|
||||||
{
|
{
|
||||||
// 当前没有连接 则首先进行数据库连接
|
// 当前没有连接 则首先进行数据库连接
|
||||||
if (!$this->_linkID) {
|
if (!$this->linkID) {
|
||||||
$this->initConnect($master);
|
$this->initConnect($master);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,7 +100,7 @@ class Mongo extends Driver
|
|||||||
// 传人Db则切换数据库
|
// 传人Db则切换数据库
|
||||||
// 当前MongoDb对象
|
// 当前MongoDb对象
|
||||||
$this->_dbName = $db;
|
$this->_dbName = $db;
|
||||||
$this->_mongo = $this->_linkID->selectDb($db);
|
$this->_mongo = $this->linkID->selectDb($db);
|
||||||
}
|
}
|
||||||
// 当前MongoCollection对象
|
// 当前MongoCollection对象
|
||||||
if ($this->config['debug']) {
|
if ($this->config['debug']) {
|
||||||
@@ -176,9 +176,9 @@ class Mongo extends Driver
|
|||||||
*/
|
*/
|
||||||
public function close()
|
public function close()
|
||||||
{
|
{
|
||||||
if ($this->_linkID) {
|
if ($this->linkID) {
|
||||||
$this->_linkID->close();
|
$this->linkID->close();
|
||||||
$this->_linkID = null;
|
$this->linkID = null;
|
||||||
$this->_mongo = null;
|
$this->_mongo = null;
|
||||||
$this->_collection = null;
|
$this->_collection = null;
|
||||||
$this->_cursor = null;
|
$this->_cursor = null;
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ class Oracle extends Driver
|
|||||||
public function execute($str, $bind = [])
|
public function execute($str, $bind = [])
|
||||||
{
|
{
|
||||||
$this->initConnect(true);
|
$this->initConnect(true);
|
||||||
if (!$this->_linkID) {
|
if (!$this->linkID) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,12 +69,12 @@ class Oracle extends Driver
|
|||||||
try {
|
try {
|
||||||
// 记录开始执行时间
|
// 记录开始执行时间
|
||||||
$this->debug(true);
|
$this->debug(true);
|
||||||
$this->PDOStatement = $this->_linkID->prepare($str);
|
$this->PDOStatement = $this->linkID->prepare($str);
|
||||||
$result = $this->PDOStatement->execute($bind);
|
$result = $this->PDOStatement->execute($bind);
|
||||||
$this->debug(false);
|
$this->debug(false);
|
||||||
$this->numRows = $this->PDOStatement->rowCount();
|
$this->numRows = $this->PDOStatement->rowCount();
|
||||||
if ($flag || preg_match("/^\s*(INSERT\s+INTO|REPLACE\s+INTO)\s+/i", $str)) {
|
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;
|
return $this->numRows;
|
||||||
} catch (\PDOException $e) {
|
} catch (\PDOException $e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user