PHP 클래스 Cml\Db\MySql\Pdo

상속: extends Cml\Db\MySql\Base
파일 보기 프로젝트 열기: linhecheng/cmlphp

보호된 프로퍼티들

프로퍼티 타입 설명
$openCache boolean 启用数据缓存

공개 메소드들

메소드 설명
__construct ( $conf ) 数据库连接串
__destruct ( ) 析构函数
affectedRows ( $handle, integer $type ) : integer 返回INSERT,UPDATE 或 DELETE 查询所影响的记录行数。
avg ( string $field = 'id', boolean | string $isMulti = false, boolean | string $useMaster = false ) : mixed 获取 AVG(字段名) 的结果
buildSql ( null $offset = null, null $limit = null, boolean $isSelect = false ) : string | array 构建sql
callProcedure ( string $procedureName = '', array $bindParams = [], boolean | true $isSelect = true ) : array | integer 调用存储过程
close ( ) 关闭连接
commit ( ) : boolean 提交事务
connect ( string $host, string $username, string $password, string $dbName, string $charset = 'utf8', string $engine = '', boolean $pConnect = false ) : mixed Db连接
count ( string $field = '*', boolean | string $isMulti = false, boolean | string $useMaster = false ) : mixed 获取 COUNT(字段名或*) 的结果
decrement ( string $key, integer $val = 1, string $field = null, mixed $tablePrefix = null ) : boolean 指定字段的值-1
delete ( string $key = '', boolean $and = true, mixed $tablePrefix = null ) : boolean 根据key值删除数据
execute ( object $stmt, boolean $clearBindParams = true ) : boolean 执行预处理语句
forceIndex ( string $table, string $index, string $tablePrefix = null ) 强制使用索引
get ( string $key, boolean $and = true, boolean | string $useMaster = false, null | string $tablePrefix = null ) : array 根据key取出数据
getAllTableStatus ( ) : array 获取当前数据库中所有表的信息
getDbFields ( string $table, mixed $tablePrefix = null, integer $filter ) : mixed 获取表字段
getTables ( ) : array 获取当前db所有表名
increment ( string $key, integer $val = 1, string $field = null, mixed $tablePrefix = null ) : boolean 指定字段的值+1
insertId ( PDO $link = null ) : integer 获取上一INSERT的主键值
max ( string $field = 'id', boolean | string $isMulti = false, boolean | string $useMaster = false ) : mixed 获取 MAX(字段名) 的结果
min ( string $field = 'id', boolean | string $isMulti = false, boolean | string $useMaster = false ) : mixed 获取 MIN(字段名) 的结果
prepare ( string $sql, PDO $link = null, boolean $resetParams = true ) : PDOStatement 预处理语句
rollBack ( boolean $rollBackTo = false ) : boolean 回滚事务
savePoint ( string $pointName ) : boolean 设置一个事务保存点
select ( integer $offset = null, integer $limit = null, boolean $useMaster = false ) : array 获取多条数据
set ( string $table, array $data, mixed $tablePrefix = null ) : boolean | integer 根据key 新增 一条数据
startTransAction ( ) : boolean 开启事务
sum ( string $field = 'id', boolean | string $isMulti = false, boolean | string $useMaster = false ) : mixed 获取 SUM(字段名) 的结果
truncate ( string $tableName ) : boolean 根据表名删除数据 这个操作太危险慎用。不过一般情况程序也没这个权限
update ( string $key, array | null $data = null, boolean $and = true, mixed $tablePrefix = null ) : boolean 根据key更新一条数据
version ( PDO $link = null ) : string 获取mysql 版本

비공개 메소드들

메소드 설명
aggregation ( string $field, boolean | string $isMulti = false, boolean | string $useMaster = false, string $operation = 'COUNT' ) : mixed 获取max(字段名)的结果
buildDebugSql ( ) : string 组装sql用于DEBUG
debugLogSql ( integer $type = Debug::SQL_TYPE_NORMAL, integer $other ) Debug模式记录查询语句显示到控制台
getRealTableName ( $table ) : string 获取处理后的表名
tableFactory ( boolean $isRead = true ) : array table组装工厂

메소드 상세

__construct() 공개 메소드

数据库连接串
public __construct ( $conf )
$conf

__destruct() 공개 메소드

析构函数
public __destruct ( )

affectedRows() 공개 메소드

返回INSERT,UPDATE 或 DELETE 查询所影响的记录行数。
public affectedRows ( $handle, integer $type ) : integer
$handle \PDOStatement
$type integer 执行的类型1:insert、2:update、3:delete
리턴 integer

avg() 공개 메소드

获取 AVG(字段名) 的结果
public avg ( string $field = 'id', boolean | string $isMulti = false, boolean | string $useMaster = false ) : mixed
$field string 要统计的字段名
$isMulti boolean | string 结果集是否为多条 默认只有一条。传字符串时相当于执行了 groupBy($isMulti)
$useMaster boolean | string 是否使用主库 默认读取从库
리턴 mixed

buildSql() 공개 메소드

构建sql
public buildSql ( null $offset = null, null $limit = null, boolean $isSelect = false ) : string | array
$offset null 偏移量
$limit null 返回的条数
$isSelect boolean 是否为select调用, 是则不重置查询参数并返回cacheKey/否则直接返回sql并重置查询参数
리턴 string | array

callProcedure() 공개 메소드

调用存储过程
public callProcedure ( string $procedureName = '', array $bindParams = [], boolean | true $isSelect = true ) : array | integer
$procedureName string 要调用的存储过程名称
$bindParams array 绑定的参数
$isSelect boolean | true 是否为返回数据集的语句
리턴 array | integer

close() 공개 메소드

关闭连接
public close ( )

commit() 공개 메소드

提交事务
public commit ( ) : boolean
리턴 boolean

connect() 공개 메소드

Db连接
public connect ( string $host, string $username, string $password, string $dbName, string $charset = 'utf8', string $engine = '', boolean $pConnect = false ) : mixed
$host string 数据库host
$username string 数据库用户名
$password string 数据库密码
$dbName string 数据库名
$charset string 字符集
$engine string 引擎
$pConnect boolean 是否为长连接
리턴 mixed

count() 공개 메소드

获取 COUNT(字段名或*) 的结果
public count ( string $field = '*', boolean | string $isMulti = false, boolean | string $useMaster = false ) : mixed
$field string 要统计的字段名
$isMulti boolean | string 结果集是否为多条 默认只有一条。传字符串时相当于执行了 groupBy($isMulti)
$useMaster boolean | string 是否使用主库 默认读取从库
리턴 mixed

decrement() 공개 메소드

指定字段的值-1
public decrement ( string $key, integer $val = 1, string $field = null, mixed $tablePrefix = null ) : boolean
$key string 操作的key user-id-1
$val integer
$field string 要改变的字段
$tablePrefix mixed 表前缀 不传则获取配置中配置的前缀
리턴 boolean

delete() 공개 메소드

根据key值删除数据
public delete ( string $key = '', boolean $and = true, mixed $tablePrefix = null ) : boolean
$key string eg: 'user-uid-$uid'
$and boolean 多个条件之间是否为and true为and false为or
$tablePrefix mixed 表前缀 不传则获取配置中配置的前缀
리턴 boolean

execute() 공개 메소드

执行预处理语句
public execute ( object $stmt, boolean $clearBindParams = true ) : boolean
$stmt object PDOStatement
$clearBindParams boolean
리턴 boolean

forceIndex() 공개 메소드

强制使用索引
public forceIndex ( string $table, string $index, string $tablePrefix = null )
$table string 要强制索引的表名(不带前缀)
$index string 要强制使用的索引
$tablePrefix string 表前缀 不传则获取配置中配置的前缀

get() 공개 메소드

根据key取出数据
public get ( string $key, boolean $and = true, boolean | string $useMaster = false, null | string $tablePrefix = null ) : array
$key string get('user-uid-123');
$and boolean 多个条件之间是否为and true为and false为or
$useMaster boolean | string 是否使用主库 默认读取从库 此选项为字符串时为表前缀$tablePrefix
$tablePrefix null | string 表前缀
리턴 array

getAllTableStatus() 공개 메소드

获取当前数据库中所有表的信息
public getAllTableStatus ( ) : array
리턴 array

getDbFields() 공개 메소드

获取表字段
public getDbFields ( string $table, mixed $tablePrefix = null, integer $filter ) : mixed
$table string 表名
$tablePrefix mixed 表前缀 为null时代表table已经带了前缀
$filter integer 0 获取表字段详细信息数组 1获取字段以,号相隔组成的字符串
리턴 mixed

getTables() 공개 메소드

获取当前db所有表名
public getTables ( ) : array
리턴 array

increment() 공개 메소드

指定字段的值+1
public increment ( string $key, integer $val = 1, string $field = null, mixed $tablePrefix = null ) : boolean
$key string 操作的key user-id-1
$val integer
$field string 要改变的字段
$tablePrefix mixed 表前缀 不传则获取配置中配置的前缀
리턴 boolean

insertId() 공개 메소드

获取上一INSERT的主键值
public insertId ( PDO $link = null ) : integer
$link PDO
리턴 integer

max() 공개 메소드

获取 MAX(字段名) 的结果
public max ( string $field = 'id', boolean | string $isMulti = false, boolean | string $useMaster = false ) : mixed
$field string 要统计的字段名
$isMulti boolean | string 结果集是否为多条 默认只有一条。传字符串时相当于执行了 groupBy($isMulti)
$useMaster boolean | string 是否使用主库 默认读取从库
리턴 mixed

min() 공개 메소드

获取 MIN(字段名) 的结果
public min ( string $field = 'id', boolean | string $isMulti = false, boolean | string $useMaster = false ) : mixed
$field string 要统计的字段名
$isMulti boolean | string 结果集是否为多条 默认只有一条。传字符串时相当于执行了 groupBy($isMulti)
$useMaster boolean | string 是否使用主库 默认读取从库
리턴 mixed

prepare() 공개 메소드

预处理语句
public prepare ( string $sql, PDO $link = null, boolean $resetParams = true ) : PDOStatement
$sql string 要预处理的sql语句
$link PDO
$resetParams boolean
리턴 PDOStatement

rollBack() 공개 메소드

回滚事务
public rollBack ( boolean $rollBackTo = false ) : boolean
$rollBackTo boolean 是否为还原到某个保存点
리턴 boolean

savePoint() 공개 메소드

设置一个事务保存点
public savePoint ( string $pointName ) : boolean
$pointName string
리턴 boolean

select() 공개 메소드

获取多条数据
public select ( integer $offset = null, integer $limit = null, boolean $useMaster = false ) : array
$offset integer 偏移量
$limit integer 返回的条数
$useMaster boolean 是否使用主库 默认读取从库
리턴 array

set() 공개 메소드

根据key 新增 一条数据
public set ( string $table, array $data, mixed $tablePrefix = null ) : boolean | integer
$table string
$data array eg: ['username'=>'admin', 'email'=>'[email protected]']
$tablePrefix mixed 表前缀 不传则获取配置中配置的前缀
리턴 boolean | integer

startTransAction() 공개 메소드

开启事务
public startTransAction ( ) : boolean
리턴 boolean

sum() 공개 메소드

获取 SUM(字段名) 的结果
public sum ( string $field = 'id', boolean | string $isMulti = false, boolean | string $useMaster = false ) : mixed
$field string 要统计的字段名
$isMulti boolean | string 结果集是否为多条 默认只有一条。传字符串时相当于执行了 groupBy($isMulti)
$useMaster boolean | string 是否使用主库 默认读取从库
리턴 mixed

truncate() 공개 메소드

根据表名删除数据 这个操作太危险慎用。不过一般情况程序也没这个权限
public truncate ( string $tableName ) : boolean
$tableName string 要清空的表名
리턴 boolean

update() 공개 메소드

根据key更新一条数据
public update ( string $key, array | null $data = null, boolean $and = true, mixed $tablePrefix = null ) : boolean
$key string eg 'user-uid-$uid' 如果条件是通用whereXX()、表名是通过table()设定。这边可以直接传$data的数组
$data array | null
$and boolean 多个条件之间是否为and true为and false为or
$tablePrefix mixed 表前缀 不传则获取配置中配置的前缀
리턴 boolean

version() 공개 메소드

获取mysql 版本
public version ( PDO $link = null ) : string
$link PDO
리턴 string

프로퍼티 상세

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

启用数据缓存
protected bool $openCache
리턴 boolean