PHP Class Think\Db\Connection

Mostrar archivo Open project: top-think/framework

Protected Properties

Property Type Description
$PDOStatement PDO操作实例
$attrCase 字段属性大小写
$config 数据库连接参数配置
$error 错误信息
$event 监听回调
$fetchType 查询结果类型
$linkID 当前连接ID
$linkRead
$linkWrite
$links 数据库连接ID 支持多个连接
$numRows 返回或者影响记录数
$params PDO连接参数
$query 查询对象
$queryStr 当前SQL指令
$resultSetType 查询结果类型
$transTimes 事务指令数

Public Methods

Method Description
__call ( string $method, array $args ) : mixed 调用Query类的查询方法
__construct ( array $config = [] ) 架构函数 读取数据库配置信息
__destruct ( ) 析构方法
batchQuery ( array $sqlArray = [] ) : boolean 批处理执行SQL语句 批处理的指令都认为是execute操作
close ( ) 关闭数据库
commit ( ) : void 用于非自动提交状态下面的查询提交
connect ( array $config = [], integer $linkNum, array | boolean $autoConnection = false ) : PDO 连接数据库方法
execute ( string $sql, array $bind = [] ) : integer 执行语句
fieldCase ( array $info ) : array 对返数据表字段信息进行大小写转换出来
free ( ) 释放查询结果
getConfig ( string $config = '' ) : mixed 获取数据库的配置参数
getError ( ) : string 获取最近的错误信息
getExecuteTimes ( ) : integer 获得执行次数
getFields ( string $tableName ) : array 取得数据表的字段信息
getLastInsID ( string $sequence = null ) : string 获取最近插入的ID
getLastSql ( ) : string 获取最近一次查询的sql语句
getNumRows ( ) : integer 获取返回或者影响的记录数
getPdo ( ) : PDO | false 获取PDO对象
getQueryTimes ( boolean $execute = false ) : integer 获得查询次数
getRealSql ( string $sql, array $bind = [] ) : string 根据参数绑定组装最终的SQL语句 便于调试
getTables ( string $dbName ) : array 取得数据库的表信息
listen ( callable $callback ) : void 监听SQL执行
model ( string $model, string $queryClass = '' ) : Query 创建指定模型的查询对象
query ( string $sql, array $bind = [], boolean $master = false, boolean | string $class = false ) : mixed 执行查询 返回数据集
quote ( string $str, boolean $master = true ) : string SQL指令安全过滤
rollback ( ) : void 事务回滚
setConfig ( string | array $config, mixed $value = '' ) : void 设置数据库的配置参数
startTrans ( ) : void 启动事务
transaction ( callable $callback ) : mixed 执行数据库事务

Protected Methods

Method Description
bindValue ( array $bind = [] ) : void 参数绑定 支持 ['name'=>'value','id'=>123] 对应命名占位符 或者 ['value',123] 对应问号占位符
debug ( boolean $start, string $sql = '' ) : void 数据库调试 记录当前SQL及分析性能
getExplain ( string $sql ) : array SQL性能分析
getResult ( boolean | string $class = '', boolean $procedure = false ) : mixed 获得数据集
initConnect ( boolean $master = true ) : void 初始化数据库连接
multiConnect ( boolean $master = false ) : PDO 连接分布式服务器
parseDsn ( array $config ) : string 解析pdo连接的dsn信息
parseSavepoint ( $name ) : string 生成定义保存点的SQL
parseSavepointRollBack ( $name ) : string 生成回滚到保存点的SQL
procedure ( boolean | string $class ) : array 获得存储过程数据集
supportSavepoint ( ) : boolean 是否支持事务嵌套
trigger ( string $sql, float $runtime, mixed $explain = [] ) : boolean 触发SQL事件

Method Details

__call() public method

调用Query类的查询方法
public __call ( string $method, array $args ) : mixed
$method string 方法名称
$args array 调用参数
return mixed

__construct() public method

架构函数 读取数据库配置信息
public __construct ( array $config = [] )
$config array 数据库配置数组

__destruct() public method

析构方法
public __destruct ( )

batchQuery() public method

批处理执行SQL语句 批处理的指令都认为是execute操作
public batchQuery ( array $sqlArray = [] ) : boolean
$sqlArray array SQL批处理指令
return boolean

bindValue() protected method

参数绑定 支持 ['name'=>'value','id'=>123] 对应命名占位符 或者 ['value',123] 对应问号占位符
protected bindValue ( array $bind = [] ) : void
$bind array 要绑定的参数列表
return void

close() public method

关闭数据库
public close ( )

commit() public method

用于非自动提交状态下面的查询提交
public commit ( ) : void
return void

connect() public method

连接数据库方法
public connect ( array $config = [], integer $linkNum, array | boolean $autoConnection = false ) : PDO
$config array 连接参数
$linkNum integer 连接序号
$autoConnection array | boolean 是否自动连接主数据库(用于分布式)
return PDO

debug() protected method

数据库调试 记录当前SQL及分析性能
protected debug ( boolean $start, string $sql = '' ) : void
$start boolean 调试开始标记 true 开始 false 结束
$sql string 执行的SQL语句 留空自动获取
return void

execute() public method

执行语句
public execute ( string $sql, array $bind = [] ) : integer
$sql string sql指令
$bind array 参数绑定
return integer

fieldCase() public method

对返数据表字段信息进行大小写转换出来
public fieldCase ( array $info ) : array
$info array 字段信息
return array

free() public method

释放查询结果
public free ( )

getConfig() public method

获取数据库的配置参数
public getConfig ( string $config = '' ) : mixed
$config string 配置名称
return mixed

getError() public method

获取最近的错误信息
public getError ( ) : string
return string

getExecuteTimes() public method

获得执行次数
public getExecuteTimes ( ) : integer
return integer

getExplain() abstract protected method

SQL性能分析
abstract protected getExplain ( string $sql ) : array
$sql string
return array

getFields() abstract public method

取得数据表的字段信息
abstract public getFields ( string $tableName ) : array
$tableName string
return array

getLastInsID() public method

获取最近插入的ID
public getLastInsID ( string $sequence = null ) : string
$sequence string 自增序列名
return string

getLastSql() public method

获取最近一次查询的sql语句
public getLastSql ( ) : string
return string

getNumRows() public method

获取返回或者影响的记录数
public getNumRows ( ) : integer
return integer

getPdo() public method

获取PDO对象
public getPdo ( ) : PDO | false
return PDO | false

getQueryTimes() public method

获得查询次数
public getQueryTimes ( boolean $execute = false ) : integer
$execute boolean 是否包含所有查询
return integer

getRealSql() public method

根据参数绑定组装最终的SQL语句 便于调试
public getRealSql ( string $sql, array $bind = [] ) : string
$sql string 带参数绑定的sql语句
$bind array 参数绑定列表
return string

getResult() protected method

获得数据集
protected getResult ( boolean | string $class = '', boolean $procedure = false ) : mixed
$class boolean | string true 返回PDOStatement 字符串用于指定返回的类名
$procedure boolean 是否存储过程
return mixed

getTables() abstract public method

取得数据库的表信息
abstract public getTables ( string $dbName ) : array
$dbName string
return array

initConnect() protected method

初始化数据库连接
protected initConnect ( boolean $master = true ) : void
$master boolean 是否主服务器
return void

listen() public method

监听SQL执行
public listen ( callable $callback ) : void
$callback callable 回调方法
return void

model() public method

创建指定模型的查询对象
public model ( string $model, string $queryClass = '' ) : Query
$model string 模型类名称
$queryClass string 查询对象类名
return Query

multiConnect() protected method

连接分布式服务器
protected multiConnect ( boolean $master = false ) : PDO
$master boolean 主服务器
return PDO

parseDsn() abstract protected method

解析pdo连接的dsn信息
abstract protected parseDsn ( array $config ) : string
$config array 连接信息
return string

parseSavepoint() protected method

生成定义保存点的SQL
protected parseSavepoint ( $name ) : string
$name
return string

parseSavepointRollBack() protected method

生成回滚到保存点的SQL
protected parseSavepointRollBack ( $name ) : string
$name
return string

procedure() protected method

获得存储过程数据集
protected procedure ( boolean | string $class ) : array
$class boolean | string true 返回PDOStatement 字符串用于指定返回的类名
return array

query() public method

执行查询 返回数据集
public query ( string $sql, array $bind = [], boolean $master = false, boolean | string $class = false ) : mixed
$sql string sql指令
$bind array 参数绑定
$master boolean 是否在主服务器读操作
$class boolean | string 指定返回的数据集对象
return mixed

quote() public method

SQL指令安全过滤
public quote ( string $str, boolean $master = true ) : string
$str string SQL字符串
$master boolean 是否主库查询
return string

rollback() public method

事务回滚
public rollback ( ) : void
return void

setConfig() public method

设置数据库的配置参数
public setConfig ( string | array $config, mixed $value = '' ) : void
$config string | array 配置名称
$value mixed 配置值
return void

startTrans() public method

启动事务
public startTrans ( ) : void
return void

supportSavepoint() protected method

是否支持事务嵌套
protected supportSavepoint ( ) : boolean
return boolean

transaction() public method

执行数据库事务
public transaction ( callable $callback ) : mixed
$callback callable 数据操作方法回调
return mixed

trigger() protected method

触发SQL事件
protected trigger ( string $sql, float $runtime, mixed $explain = [] ) : boolean
$sql string SQL语句
$runtime float SQL运行时间
$explain mixed SQL分析
return boolean

Property Details

$PDOStatement protected_oe property

PDO操作实例
protected $PDOStatement

$attrCase protected_oe property

字段属性大小写
protected $attrCase

$config protected_oe property

数据库连接参数配置
protected $config

$error protected_oe property

错误信息
protected $error

$event protected_oe static_oe property

监听回调
protected static $event

$fetchType protected_oe property

查询结果类型
protected $fetchType

$linkID protected_oe property

当前连接ID
protected $linkID

$linkRead protected_oe property

protected $linkRead

$linkWrite protected_oe property

protected $linkWrite

$numRows protected_oe property

返回或者影响记录数
protected $numRows

$params protected_oe property

PDO连接参数
protected $params

$query protected_oe property

查询对象
protected $query

$queryStr protected_oe property

当前SQL指令
protected $queryStr

$resultSetType protected_oe property

查询结果类型
protected $resultSetType

$transTimes protected_oe property

事务指令数
protected $transTimes