mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-06 23:02:48 +08:00
改进
This commit is contained in:
@@ -17,9 +17,9 @@ namespace think;
|
|||||||
class Db
|
class Db
|
||||||
{
|
{
|
||||||
// 数据库连接实例
|
// 数据库连接实例
|
||||||
private static $instance = [];
|
private static $instance = [];
|
||||||
// 当前数据库连接实例
|
// 当前数据库连接实例
|
||||||
private static $_instance = null;
|
private static $_instance = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 取得数据库类实例
|
* 取得数据库类实例
|
||||||
@@ -36,7 +36,7 @@ class Db
|
|||||||
// 解析连接参数 支持数组和字符串
|
// 解析连接参数 支持数组和字符串
|
||||||
$options = self::parseConfig($config);
|
$options = self::parseConfig($config);
|
||||||
// 如果采用lite方式 仅支持原生SQL 包括query和execute方法
|
// 如果采用lite方式 仅支持原生SQL 包括query和execute方法
|
||||||
$class = $lite ? 'think\\db\\lite' : 'think\\db\\driver\\' . strtolower($options['type']);
|
$class = $lite ? '\\think\\db\\Lite' : '\\think\\db\\driver\\' . ucwords($options['type']);
|
||||||
self::$instance[$md5] = new $class($options);
|
self::$instance[$md5] = new $class($options);
|
||||||
}
|
}
|
||||||
self::$_instance = self::$instance[$md5];
|
self::$_instance = self::$instance[$md5];
|
||||||
|
|||||||
@@ -348,7 +348,7 @@ class Lite
|
|||||||
// 记录错误日志
|
// 记录错误日志
|
||||||
Log::record($this->error, 'ERR');
|
Log::record($this->error, 'ERR');
|
||||||
if ($this->config['debug']) {
|
if ($this->config['debug']) {
|
||||||
// 开启数据库调试模式
|
// 开启数据库调试模式
|
||||||
throw new Exception($this->error);
|
throw new Exception($this->error);
|
||||||
} else {
|
} else {
|
||||||
return $this->error;
|
return $this->error;
|
||||||
@@ -416,7 +416,7 @@ class Lite
|
|||||||
protected function debug($start)
|
protected function debug($start)
|
||||||
{
|
{
|
||||||
if ($this->config['debug']) {
|
if ($this->config['debug']) {
|
||||||
// 开启数据库调试模式
|
// 开启数据库调试模式
|
||||||
if ($start) {
|
if ($start) {
|
||||||
Debug::remark('queryStartTime', 'time');
|
Debug::remark('queryStartTime', 'time');
|
||||||
} else {
|
} else {
|
||||||
@@ -437,13 +437,11 @@ class Lite
|
|||||||
*/
|
*/
|
||||||
protected function initConnect($master = true)
|
protected function initConnect($master = true)
|
||||||
{
|
{
|
||||||
if (!empty($this->config['deploy']))
|
if (!empty($this->config['deploy'])) {
|
||||||
// 采用分布式数据库
|
// 采用分布式数据库
|
||||||
{
|
|
||||||
$this->_linkID = $this->multiConnect($master);
|
$this->_linkID = $this->multiConnect($master);
|
||||||
} else
|
} elseif (!$this->_linkID) {
|
||||||
// 默认单数据库
|
// 默认单数据库
|
||||||
if (!$this->_linkID) {
|
|
||||||
$this->_linkID = $this->connect();
|
$this->_linkID = $this->connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -476,7 +474,7 @@ class Lite
|
|||||||
$r = floor(mt_rand(0, $this->config['master_num'] - 1));
|
$r = floor(mt_rand(0, $this->config['master_num'] - 1));
|
||||||
} else {
|
} else {
|
||||||
if (is_numeric($this->config['slave_no'])) {
|
if (is_numeric($this->config['slave_no'])) {
|
||||||
// 指定服务器读
|
// 指定服务器读
|
||||||
$r = $this->config['slave_no'];
|
$r = $this->config['slave_no'];
|
||||||
} else {
|
} else {
|
||||||
// 读操作连接从服务器
|
// 读操作连接从服务器
|
||||||
|
|||||||
Reference in New Issue
Block a user