mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-02 05:02:48 +08:00
改进
This commit is contained in:
@@ -17,9 +17,9 @@ namespace think;
|
||||
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);
|
||||
// 如果采用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 = self::$instance[$md5];
|
||||
|
||||
@@ -348,7 +348,7 @@ class Lite
|
||||
// 记录错误日志
|
||||
Log::record($this->error, 'ERR');
|
||||
if ($this->config['debug']) {
|
||||
// 开启数据库调试模式
|
||||
// 开启数据库调试模式
|
||||
throw new Exception($this->error);
|
||||
} else {
|
||||
return $this->error;
|
||||
@@ -416,7 +416,7 @@ class Lite
|
||||
protected function debug($start)
|
||||
{
|
||||
if ($this->config['debug']) {
|
||||
// 开启数据库调试模式
|
||||
// 开启数据库调试模式
|
||||
if ($start) {
|
||||
Debug::remark('queryStartTime', 'time');
|
||||
} else {
|
||||
@@ -437,13 +437,11 @@ class Lite
|
||||
*/
|
||||
protected function initConnect($master = true)
|
||||
{
|
||||
if (!empty($this->config['deploy']))
|
||||
// 采用分布式数据库
|
||||
{
|
||||
if (!empty($this->config['deploy'])) {
|
||||
// 采用分布式数据库
|
||||
$this->_linkID = $this->multiConnect($master);
|
||||
} else
|
||||
// 默认单数据库
|
||||
if (!$this->_linkID) {
|
||||
} elseif (!$this->_linkID) {
|
||||
// 默认单数据库
|
||||
$this->_linkID = $this->connect();
|
||||
}
|
||||
|
||||
@@ -476,7 +474,7 @@ class Lite
|
||||
$r = floor(mt_rand(0, $this->config['master_num'] - 1));
|
||||
} else {
|
||||
if (is_numeric($this->config['slave_no'])) {
|
||||
// 指定服务器读
|
||||
// 指定服务器读
|
||||
$r = $this->config['slave_no'];
|
||||
} else {
|
||||
// 读操作连接从服务器
|
||||
|
||||
Reference in New Issue
Block a user