注释改进

This commit is contained in:
thinkphp
2016-05-18 12:30:55 +08:00
parent 5dc8cd481e
commit a00c4c51fe
4 changed files with 47 additions and 34 deletions

View File

@@ -23,7 +23,7 @@ class Db
// 自定义对象数据集 // 自定义对象数据集
const RESULTSET_CLASS = 3; const RESULTSET_CLASS = 3;
// 数据库连接实例 // 数据库连接实例
private static $instances = []; private static $instance = [];
// 查询次数 // 查询次数
public static $queryTimes = 0; public static $queryTimes = 0;
// 执行次数 // 执行次数
@@ -35,7 +35,7 @@ class Db
* @access public * @access public
* @param mixed $config 连接配置 * @param mixed $config 连接配置
* @param bool|string $name 连接标识 true 强制重新连接 * @param bool|string $name 连接标识 true 强制重新连接
* @return db\Connection * @return \think\db\Connection
* @throws Exception * @throws Exception
*/ */
public static function connect($config = [], $name = false) public static function connect($config = [], $name = false)
@@ -43,7 +43,7 @@ class Db
if (false === $name) { if (false === $name) {
$name = md5(serialize($config)); $name = md5(serialize($config));
} }
if (true === $name || !isset(self::$instances[$name])) { if (true === $name || !isset(self::$instance[$name])) {
// 解析连接参数 支持数组和字符串 // 解析连接参数 支持数组和字符串
$options = self::parseConfig($config); $options = self::parseConfig($config);
if (empty($options['type'])) { if (empty($options['type'])) {
@@ -55,10 +55,10 @@ class Db
if (true === $name) { if (true === $name) {
return new $class($options); return new $class($options);
} else { } else {
self::$instances[$name] = new $class($options); self::$instance[$name] = new $class($options);
} }
} }
return self::$instances[$name]; return self::$instance[$name];
} }
/** /**

View File

@@ -50,8 +50,6 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
protected $hidden = []; protected $hidden = [];
// 数据信息 // 数据信息
protected $data = []; protected $data = [];
// 缓存数据
protected $cache = [];
// 记录改变字段 // 记录改变字段
protected $change = []; protected $change = [];

View File

@@ -595,22 +595,23 @@ abstract class Connection
* 批处理执行SQL语句 * 批处理执行SQL语句
* 批处理的指令都认为是execute操作 * 批处理的指令都认为是execute操作
* @access public * @access public
* @param array $sql SQL批处理指令 * @param array $sqlArray SQL批处理指令
* @return boolean * @return boolean
*/ */
public function batchQuery($sql = []) public function batchQuery($sqlArray = [])
{ {
if (!is_array($sql)) { if (!is_array($sqlArray)) {
return false; return false;
} }
// 自动启动事务支持 // 自动启动事务支持
$this->startTrans(NOW_TIME); $label = microtime(true);
$this->startTrans($label);
try { try {
foreach ($sql as $_sql) { foreach ($sqlArray as $sql) {
$result = $this->execute($_sql); $result = $this->execute($sql);
} }
// 提交事务 // 提交事务
$this->commit(NOW_TIME); $this->commit($label);
} catch (\PDOException $e) { } catch (\PDOException $e) {
$this->rollback(); $this->rollback();
return false; return false;
@@ -717,9 +718,10 @@ abstract class Connection
} }
/** /**
* 数据库调试 记录当前SQL * 数据库调试 记录当前SQL及分析性能
* @access protected * @access protected
* @param boolean $start 调试开始标记 true 开始 false 结束 * @param boolean $start 调试开始标记 true 开始 false 结束
* @return void
*/ */
protected function debug($start) protected function debug($start)
{ {
@@ -782,7 +784,7 @@ abstract class Connection
/** /**
* 初始化数据库连接 * 初始化数据库连接
* @access protected * @access protected
* @param boolean $master 主服务器 * @param boolean $master 是否主服务器
* @return void * @return void
*/ */
protected function initConnect($master = true) protected function initConnect($master = true)

View File

@@ -44,6 +44,7 @@ class Query
* 架构函数 * 架构函数
* @access public * @access public
* @param \think\db\Connection|string $connection 数据库对象实例 * @param \think\db\Connection|string $connection 数据库对象实例
* @param string $model 模型名
* @throws Exception * @throws Exception
*/ */
public function __construct($connection = '', $model = '') 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 * @access public
* @param string $table 表名 * @param string $table 表名
* @return $this * @return $this
@@ -1046,23 +1059,11 @@ class Query
return $this; return $this;
} }
/**
* 设置当前name
* @access public
* @param string $name
* @return $this
*/
public function name($name)
{
$this->name = $name;
return $this;
}
/** /**
* 获取数据表信息 * 获取数据表信息
* @access public * @access public
* @param string $fetch 获取信息类型 包括 fields type bind pk
* @param string $tableName 数据表名 留空自动获取 * @param string $tableName 数据表名 留空自动获取
* @param string $fetch 获取信息类型 包括 fields type bind pk
* @return mixed * @return mixed
*/ */
public function getTableInfo($tableName = '', $fetch = '') public function getTableInfo($tableName = '', $fetch = '')
@@ -1113,7 +1114,7 @@ class Query
* 获取当前模型对象的主键 * 获取当前模型对象的主键
* @access public * @access public
* @param string $table 数据表名 * @param string $table 数据表名
* @return mixed * @return string|array
*/ */
public function getPk($table = '') public function getPk($table = '')
{ {
@@ -1138,6 +1139,12 @@ class Query
return $this; return $this;
} }
/**
* 检测参数是否已经绑定
* @access public
* @param string $key 参数名
* @return bool
*/
public function isBind($key) public function isBind($key)
{ {
return isset($this->bind[$key]); return isset($this->bind[$key]);
@@ -1155,6 +1162,12 @@ class Query
return $this; return $this;
} }
/**
* 获取当前的查询参数
* @access public
* @param string $name 参数名
* @return mixed
*/
public function getOptions($name = '') public function getOptions($name = '')
{ {
return isset($this->options[$name]) ? $this->options[$name] : $this->options; return isset($this->options[$name]) ? $this->options[$name] : $this->options;
@@ -1164,7 +1177,7 @@ class Query
* 设置关联查询JOIN预查询 * 设置关联查询JOIN预查询
* @access public * @access public
* @param string|array $with 关联方法名称 * @param string|array $with 关联方法名称
* @return Db * @return $this
*/ */
public function with($with) public function with($with)
{ {
@@ -1225,7 +1238,7 @@ class Query
* 设置当前字段添加的表别名 * 设置当前字段添加的表别名
* @access public * @access public
* @param string $via * @param string $via
* @return Db * @return $this
*/ */
public function via($via = '') public function via($via = '')
{ {
@@ -1237,7 +1250,7 @@ class Query
* 设置关联查询 * 设置关联查询
* @access public * @access public
* @param string $relation 关联名称 * @param string $relation 关联名称
* @return Db * @return $this
*/ */
public function relation($relation) public function relation($relation)
{ {