mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
注释改进
This commit is contained in:
@@ -23,7 +23,7 @@ class Db
|
||||
// 自定义对象数据集
|
||||
const RESULTSET_CLASS = 3;
|
||||
// 数据库连接实例
|
||||
private static $instances = [];
|
||||
private static $instance = [];
|
||||
// 查询次数
|
||||
public static $queryTimes = 0;
|
||||
// 执行次数
|
||||
@@ -35,7 +35,7 @@ class Db
|
||||
* @access public
|
||||
* @param mixed $config 连接配置
|
||||
* @param bool|string $name 连接标识 true 强制重新连接
|
||||
* @return db\Connection
|
||||
* @return \think\db\Connection
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function connect($config = [], $name = false)
|
||||
@@ -43,7 +43,7 @@ class Db
|
||||
if (false === $name) {
|
||||
$name = md5(serialize($config));
|
||||
}
|
||||
if (true === $name || !isset(self::$instances[$name])) {
|
||||
if (true === $name || !isset(self::$instance[$name])) {
|
||||
// 解析连接参数 支持数组和字符串
|
||||
$options = self::parseConfig($config);
|
||||
if (empty($options['type'])) {
|
||||
@@ -55,10 +55,10 @@ class Db
|
||||
if (true === $name) {
|
||||
return new $class($options);
|
||||
} else {
|
||||
self::$instances[$name] = new $class($options);
|
||||
self::$instance[$name] = new $class($options);
|
||||
}
|
||||
}
|
||||
return self::$instances[$name];
|
||||
return self::$instance[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -50,8 +50,6 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
protected $hidden = [];
|
||||
// 数据信息
|
||||
protected $data = [];
|
||||
// 缓存数据
|
||||
protected $cache = [];
|
||||
// 记录改变字段
|
||||
protected $change = [];
|
||||
|
||||
|
||||
@@ -595,22 +595,23 @@ abstract class Connection
|
||||
* 批处理执行SQL语句
|
||||
* 批处理的指令都认为是execute操作
|
||||
* @access public
|
||||
* @param array $sql SQL批处理指令
|
||||
* @param array $sqlArray SQL批处理指令
|
||||
* @return boolean
|
||||
*/
|
||||
public function batchQuery($sql = [])
|
||||
public function batchQuery($sqlArray = [])
|
||||
{
|
||||
if (!is_array($sql)) {
|
||||
if (!is_array($sqlArray)) {
|
||||
return false;
|
||||
}
|
||||
// 自动启动事务支持
|
||||
$this->startTrans(NOW_TIME);
|
||||
$label = microtime(true);
|
||||
$this->startTrans($label);
|
||||
try {
|
||||
foreach ($sql as $_sql) {
|
||||
$result = $this->execute($_sql);
|
||||
foreach ($sqlArray as $sql) {
|
||||
$result = $this->execute($sql);
|
||||
}
|
||||
// 提交事务
|
||||
$this->commit(NOW_TIME);
|
||||
$this->commit($label);
|
||||
} catch (\PDOException $e) {
|
||||
$this->rollback();
|
||||
return false;
|
||||
@@ -717,9 +718,10 @@ abstract class Connection
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据库调试 记录当前SQL
|
||||
* 数据库调试 记录当前SQL及分析性能
|
||||
* @access protected
|
||||
* @param boolean $start 调试开始标记 true 开始 false 结束
|
||||
* @return void
|
||||
*/
|
||||
protected function debug($start)
|
||||
{
|
||||
@@ -782,7 +784,7 @@ abstract class Connection
|
||||
/**
|
||||
* 初始化数据库连接
|
||||
* @access protected
|
||||
* @param boolean $master 主服务器
|
||||
* @param boolean $master 是否主服务器
|
||||
* @return void
|
||||
*/
|
||||
protected function initConnect($master = true)
|
||||
|
||||
@@ -44,6 +44,7 @@ class Query
|
||||
* 架构函数
|
||||
* @access public
|
||||
* @param \think\db\Connection|string $connection 数据库对象实例
|
||||
* @param string $model 模型名
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct($connection = '', $model = '')
|
||||
@@ -786,7 +787,19 @@ class Query
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定默认数据表
|
||||
* 指定默认的数据表名(不含前缀)
|
||||
* @access public
|
||||
* @param string $name
|
||||
* @return $this
|
||||
*/
|
||||
public function name($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定默认数据表名(含前缀)
|
||||
* @access public
|
||||
* @param string $table 表名
|
||||
* @return $this
|
||||
@@ -1046,23 +1059,11 @@ class Query
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置当前name
|
||||
* @access public
|
||||
* @param string $name
|
||||
* @return $this
|
||||
*/
|
||||
public function name($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据表信息
|
||||
* @access public
|
||||
* @param string $fetch 获取信息类型 包括 fields type bind pk
|
||||
* @param string $tableName 数据表名 留空自动获取
|
||||
* @param string $fetch 获取信息类型 包括 fields type bind pk
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTableInfo($tableName = '', $fetch = '')
|
||||
@@ -1113,7 +1114,7 @@ class Query
|
||||
* 获取当前模型对象的主键
|
||||
* @access public
|
||||
* @param string $table 数据表名
|
||||
* @return mixed
|
||||
* @return string|array
|
||||
*/
|
||||
public function getPk($table = '')
|
||||
{
|
||||
@@ -1138,6 +1139,12 @@ class Query
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测参数是否已经绑定
|
||||
* @access public
|
||||
* @param string $key 参数名
|
||||
* @return bool
|
||||
*/
|
||||
public function isBind($key)
|
||||
{
|
||||
return isset($this->bind[$key]);
|
||||
@@ -1155,6 +1162,12 @@ class Query
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前的查询参数
|
||||
* @access public
|
||||
* @param string $name 参数名
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOptions($name = '')
|
||||
{
|
||||
return isset($this->options[$name]) ? $this->options[$name] : $this->options;
|
||||
@@ -1164,7 +1177,7 @@ class Query
|
||||
* 设置关联查询JOIN预查询
|
||||
* @access public
|
||||
* @param string|array $with 关联方法名称
|
||||
* @return Db
|
||||
* @return $this
|
||||
*/
|
||||
public function with($with)
|
||||
{
|
||||
@@ -1225,7 +1238,7 @@ class Query
|
||||
* 设置当前字段添加的表别名
|
||||
* @access public
|
||||
* @param string $via
|
||||
* @return Db
|
||||
* @return $this
|
||||
*/
|
||||
public function via($via = '')
|
||||
{
|
||||
@@ -1237,7 +1250,7 @@ class Query
|
||||
* 设置关联查询
|
||||
* @access public
|
||||
* @param string $relation 关联名称
|
||||
* @return Db
|
||||
* @return $this
|
||||
*/
|
||||
public function relation($relation)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user