PHP 클래스 Think\Db\Connection

파일 보기 프로젝트 열기: top-think/framework

보호된 프로퍼티들

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

공개 메소드들

메소드 설명
__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 执行数据库事务

보호된 메소드들

메소드 설명
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事件

메소드 상세

__call() 공개 메소드

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

__construct() 공개 메소드

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

__destruct() 공개 메소드

析构方法
public __destruct ( )

batchQuery() 공개 메소드

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

bindValue() 보호된 메소드

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

close() 공개 메소드

关闭数据库
public close ( )

commit() 공개 메소드

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

connect() 공개 메소드

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

debug() 보호된 메소드

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

execute() 공개 메소드

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

fieldCase() 공개 메소드

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

free() 공개 메소드

释放查询结果
public free ( )

getConfig() 공개 메소드

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

getError() 공개 메소드

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

getExecuteTimes() 공개 메소드

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

getExplain() 추상적인 보호된 메소드

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

getFields() 추상적인 공개 메소드

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

getLastInsID() 공개 메소드

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

getLastSql() 공개 메소드

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

getNumRows() 공개 메소드

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

getPdo() 공개 메소드

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

getQueryTimes() 공개 메소드

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

getRealSql() 공개 메소드

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

getResult() 보호된 메소드

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

getTables() 추상적인 공개 메소드

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

initConnect() 보호된 메소드

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

listen() 공개 메소드

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

model() 공개 메소드

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

multiConnect() 보호된 메소드

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

parseDsn() 추상적인 보호된 메소드

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

parseSavepoint() 보호된 메소드

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

parseSavepointRollBack() 보호된 메소드

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

procedure() 보호된 메소드

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

query() 공개 메소드

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

quote() 공개 메소드

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

rollback() 공개 메소드

事务回滚
public rollback ( ) : void
리턴 void

setConfig() 공개 메소드

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

startTrans() 공개 메소드

启动事务
public startTrans ( ) : void
리턴 void

supportSavepoint() 보호된 메소드

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

transaction() 공개 메소드

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

trigger() 보호된 메소드

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

프로퍼티 상세

$PDOStatement 보호되어 있는 프로퍼티

PDO操作实例
protected $PDOStatement

$attrCase 보호되어 있는 프로퍼티

字段属性大小写
protected $attrCase

$config 보호되어 있는 프로퍼티

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

$error 보호되어 있는 프로퍼티

错误信息
protected $error

$event 보호되어 있는 정적으로 프로퍼티

监听回调
protected static $event

$fetchType 보호되어 있는 프로퍼티

查询结果类型
protected $fetchType

$linkID 보호되어 있는 프로퍼티

当前连接ID
protected $linkID

$linkRead 보호되어 있는 프로퍼티

protected $linkRead

$linkWrite 보호되어 있는 프로퍼티

protected $linkWrite

$numRows 보호되어 있는 프로퍼티

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

$params 보호되어 있는 프로퍼티

PDO连接参数
protected $params

$query 보호되어 있는 프로퍼티

查询对象
protected $query

$queryStr 보호되어 있는 프로퍼티

当前SQL指令
protected $queryStr

$resultSetType 보호되어 있는 프로퍼티

查询结果类型
protected $resultSetType

$transTimes 보호되어 있는 프로퍼티

事务指令数
protected $transTimes