mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 15:12:48 +08:00
改进Db类 traits\Query 更改为 traits\Transaction
This commit is contained in:
@@ -93,7 +93,7 @@ function D($name = '', $layer = MODEL_LAYER)
|
|||||||
*/
|
*/
|
||||||
function db($config = [])
|
function db($config = [])
|
||||||
{
|
{
|
||||||
return \think\Db::instance($config);
|
return \think\Db::connect($config);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -26,13 +26,13 @@ class Db
|
|||||||
public static $executeTimes = 0;
|
public static $executeTimes = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 取得数据库类实例
|
* 数据库初始化 并取得数据库类实例
|
||||||
* @static
|
* @static
|
||||||
* @access public
|
* @access public
|
||||||
* @param mixed $config 连接配置
|
* @param mixed $config 连接配置
|
||||||
* @return Object 返回数据库驱动类
|
* @return Object 返回数据库驱动类
|
||||||
*/
|
*/
|
||||||
public static function instance($config = [])
|
public static function connect($config = [])
|
||||||
{
|
{
|
||||||
$md5 = md5(serialize($config));
|
$md5 = md5(serialize($config));
|
||||||
if (!isset(self::$instances[$md5])) {
|
if (!isset(self::$instances[$md5])) {
|
||||||
@@ -63,6 +63,9 @@ class Db
|
|||||||
$status = Config::get('app_status');
|
$status = Config::get('app_status');
|
||||||
$config = $config[$status ?: 'default'];
|
$config = $config[$status ?: 'default'];
|
||||||
}
|
}
|
||||||
|
} elseif (is_string($config) && false === strpos($config, '/')) {
|
||||||
|
// 支持读取配置参数
|
||||||
|
$config = Config::get($config);
|
||||||
}
|
}
|
||||||
if (is_string($config)) {
|
if (is_string($config)) {
|
||||||
return self::parseDsn($config);
|
return self::parseDsn($config);
|
||||||
@@ -106,6 +109,10 @@ class Db
|
|||||||
// 调用驱动类的方法
|
// 调用驱动类的方法
|
||||||
public static function __callStatic($method, $params)
|
public static function __callStatic($method, $params)
|
||||||
{
|
{
|
||||||
|
if (is_null(self::$instance)) {
|
||||||
|
// 自动初始化数据库
|
||||||
|
self::connect();
|
||||||
|
}
|
||||||
return call_user_func_array([self::$instance, $method], $params);
|
return call_user_func_array([self::$instance, $method], $params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -325,7 +325,7 @@ class Loader
|
|||||||
*/
|
*/
|
||||||
public static function db($config = [])
|
public static function db($config = [])
|
||||||
{
|
{
|
||||||
return Db::instance($config);
|
return Db::connect($config);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -983,11 +983,8 @@ class Model
|
|||||||
// 创建一个新的实例
|
// 创建一个新的实例
|
||||||
if (is_string($linkId) && '' == $config) {
|
if (is_string($linkId) && '' == $config) {
|
||||||
$config = Config::get($linkId);
|
$config = Config::get($linkId);
|
||||||
} elseif (!empty($config) && is_string($config) && false === strpos($config, '/')) {
|
|
||||||
// 支持读取配置参数
|
|
||||||
$config = Config::get($config);
|
|
||||||
}
|
}
|
||||||
$this->links[$linkId] = Db::instance($config);
|
$this->links[$linkId] = Db::connect($config);
|
||||||
} elseif (null === $config) {
|
} elseif (null === $config) {
|
||||||
$this->links[$linkId]->close(); // 关闭数据库连接
|
$this->links[$linkId]->close(); // 关闭数据库连接
|
||||||
unset($this->links[$linkId]);
|
unset($this->links[$linkId]);
|
||||||
|
|||||||
2
library/think/cache/driver/Db.php
vendored
2
library/think/cache/driver/Db.php
vendored
@@ -46,7 +46,7 @@ class Db
|
|||||||
if (!empty($options)) {
|
if (!empty($options)) {
|
||||||
$this->options = array_merge($this->options, $options);
|
$this->options = array_merge($this->options, $options);
|
||||||
}
|
}
|
||||||
$this->handler = \Think\Db::instance();
|
$this->handler = \Think\Db::connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -12,10 +12,10 @@
|
|||||||
namespace think\model;
|
namespace think\model;
|
||||||
|
|
||||||
T('model/Adv');
|
T('model/Adv');
|
||||||
T('model/Query');
|
T('model/Transaction');
|
||||||
|
|
||||||
class Adv extends \think\Model
|
class Adv extends \think\Model
|
||||||
{
|
{
|
||||||
use \traits\model\Adv;
|
use \traits\model\Adv;
|
||||||
use \traits\model\Query;
|
use \traits\model\Transaction;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
namespace traits\model;
|
namespace traits\model;
|
||||||
|
|
||||||
trait Query
|
trait Transaction
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Reference in New Issue
Block a user