PHP Class Db, thinksns

Author: Scott Haefner ([email protected])
Show file Open project: medz/thinksns-4 Class Usage Examples

Public Properties

Property Type Description
$debug 是否显示调试信息 如果启用会在知识文件记录sql语句

Protected Properties

Property Type Description
$_linkID 当前连接ID
$autoFree 是否自动释放查询结果
$beginTime SQL 执行时间记录
$comparison 数据库表达式
$config 数据库连接参数配置
$connected 是否已经连接数据库
$error 错误信息
$lastInsID 最后插入ID
$linkID 数据库连接ID 支持多个连接
$numCols 返回字段数
$numRows 返回或者影响记录数
$pconnect 是否使用永久连接
$queryID 当前查询ID
$queryStr 当前SQL指令
$selectSql 查询表达式
$transTimes 事务指令数

Public Methods

Method Description
Q ( mixed $times = '' ) 查询次数更新或者查询
W ( mixed $times = '' ) 写入次数更新或者查询
__construct ( array $config = '' ) 架构函数
__destruct ( ) 析构方法
addConnect ( mixed $config, mixed $linkNum = null ) +---------------------------------------------------------- 增加数据库连接(相同类型的) +---------------------------------------------------------- +----------------------------------------------------------
close ( ) 关闭数据库
commit ( ) : boolen 用于非自动提交状态下面的查询提交
connect ( $config = '', $linkNum ) 连接数据库方法
delete ( array $options = [] ) : false | integer 删除记录
error ( ) : string 数据库错误信息 并显示当前的SQL语句
escape_string ( string $str ) : string SQL指令安全过滤
execute ( string $str ) : integer 执行语句 针对 INSERT, UPDATE 以及DELETE
free ( ) 释放查询结果
getAsFieldArray ( $field = '*', $nouse = '' ) : array 获取以传入的参数的数据结果集合
getFields ( $tableName ) 取得数据表的字段信息
getHashList ( $hashKey = '', $hashValue = '*' ) : array 获取以hashkey作为键值的hash数组
getInstance ( $config = null ) : object 获取数据库单例实例
getLastSql ( ) : string 获取最近一次查询的sql语句
getTables ( $dbName = '' ) 取得数据库的表信息
insert ( mixed $data, array $options = [] ) : false | integer 插入记录
insertAll ( mixed $datas, array $options = [] ) : false | integer +---------------------------------------------------------- 插入记录 +---------------------------------------------------------- +----------------------------------------------------------
parseDSN ( string $dsnStr ) : array +---------------------------------------------------------- DSN解析 格式: mysql://username:passwd@localhost:3306/DbName
query ( string $str ) : mixed 执行查询 主要针对 SELECT, SHOW 等指令 返回数据集
replace ( mixed $data, array $options = [] ) : false | integer 替换记录
rollback ( ) : boolen 事务回滚
select ( array $options = [] ) : array 查找记录
selectInsert ( string $fields, string $table, $options = [] ) : false | integer 通过Select方式插入记录
startTrans ( ) 启动事务
switchConnect ( integer $linkNum ) +---------------------------------------------------------- 切换数据库连接 +---------------------------------------------------------- +----------------------------------------------------------
update ( mixed $data, array $options ) : false | integer 更新记录

Protected Methods

Method Description
addSpecialChar ( mixed &$value ) : mixed 字段和表名添加` 保证指令中使用关键字不出错 针对mysql
debug ( ) 数据库调试 记录当前SQL
initConnect ( boolean $master = true ) +---------------------------------------------------------- 初始化数据库连接 +---------------------------------------------------------- +----------------------------------------------------------
multiConnect ( boolean $master = false ) +---------------------------------------------------------- 连接分布式服务器 +---------------------------------------------------------- +----------------------------------------------------------
parseDistinct ( mixed $distinct ) : string distinct分析
parseField ( mixed $fields ) : string field分析
parseGroup ( mixed $group ) : string group分析
parseHaving ( string $having ) : string having分析
parseJoin ( mixed $join ) : string join分析
parseLimit ( $limit ) : string limit分析
parseLock ( $lock = false ) : string 设置锁机制
parseOrder ( mixed $order ) : string order分析
parseSet ( array $data ) : string set分析
parseTable ( $tables ) : string table分析
parseThinkWhere ( string $key, mixed $val ) : string 特殊条件分析
parseValue ( mixed &$value ) : string value分析
parseWhere ( mixed $where ) : string where分析

Private Methods

Method Description
getAll ( ) : array 获得所有的查询数据
parseConfig ( mixed $db_config = '' ) : string 分析数据库配置信息,支持数组和DSN

Method Details

Q() public method

查询次数更新或者查询
public Q ( mixed $times = '' )
$times mixed

W() public method

写入次数更新或者查询
public W ( mixed $times = '' )
$times mixed

__construct() public method

架构函数
public __construct ( array $config = '' )
$config array 数据库配置数组

__destruct() public method

析构方法
public __destruct ( )

addConnect() public method

+---------------------------------------------------------- 增加数据库连接(相同类型的) +---------------------------------------------------------- +----------------------------------------------------------
public addConnect ( mixed $config, mixed $linkNum = null )
$config mixed 数据库连接信息
$linkNum mixed 创建的连接序号 +---------------------------------------------------------- +----------------------------------------------------------

addSpecialChar() protected method

字段和表名添加` 保证指令中使用关键字不出错 针对mysql
protected addSpecialChar ( mixed &$value ) : mixed
$value mixed
return mixed

close() public method

关闭数据库
public close ( )

commit() public method

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

connect() public method

连接数据库方法
public connect ( $config = '', $linkNum )

debug() protected method

数据库调试 记录当前SQL
protected debug ( )

delete() public method

删除记录
public delete ( array $options = [] ) : false | integer
$options array 表达式
return false | integer | integer

error() public method

数据库错误信息 并显示当前的SQL语句
public error ( ) : string
return string

escape_string() public method

SQL指令安全过滤
public escape_string ( string $str ) : string
$str string SQL字符串
return string

execute() public method

执行语句 针对 INSERT, UPDATE 以及DELETE
public execute ( string $str ) : integer
$str string sql指令
return integer

free() public method

释放查询结果
public free ( )

getAsFieldArray() public method

获取以传入的参数的数据结果集合
public getAsFieldArray ( $field = '*', $nouse = '' ) : array
return array

getFields() public method

取得数据表的字段信息
public getFields ( $tableName )

getHashList() public method

获取以hashkey作为键值的hash数组
public getHashList ( $hashKey = '', $hashValue = '*' ) : array
return array

getInstance() public static method

获取数据库单例实例
Author: Seven Du ([email protected])
public static getInstance ( $config = null ) : object
return object self

getLastSql() public method

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

getTables() public method

取得数据库的表信息
public getTables ( $dbName = '' )

initConnect() protected method

+---------------------------------------------------------- 初始化数据库连接 +---------------------------------------------------------- +----------------------------------------------------------
protected initConnect ( boolean $master = true )
$master boolean 主服务器 +---------------------------------------------------------- +----------------------------------------------------------

insert() public method

插入记录
public insert ( mixed $data, array $options = [] ) : false | integer
$data mixed 数据
$options array 参数表达式
return false | integer | integer

insertAll() public method

+---------------------------------------------------------- 插入记录 +---------------------------------------------------------- +----------------------------------------------------------
public insertAll ( mixed $datas, array $options = [] ) : false | integer
$datas mixed 数据
$options array 参数表达式 +----------------------------------------------------------
return false | integer | integer +----------------------------------------------------------

multiConnect() protected method

+---------------------------------------------------------- 连接分布式服务器 +---------------------------------------------------------- +----------------------------------------------------------
protected multiConnect ( boolean $master = false )
$master boolean 主服务器 +---------------------------------------------------------- +----------------------------------------------------------

parseDSN() public method

+---------------------------------------------------------- DSN解析 格式: mysql://username:passwd@localhost:3306/DbName
public parseDSN ( string $dsnStr ) : array
$dsnStr string
return array

parseDistinct() protected method

distinct分析
protected parseDistinct ( mixed $distinct ) : string
$distinct mixed
return string

parseField() protected method

field分析
protected parseField ( mixed $fields ) : string
$fields mixed
return string

parseGroup() protected method

group分析
protected parseGroup ( mixed $group ) : string
$group mixed
return string

parseHaving() protected method

having分析
protected parseHaving ( string $having ) : string
$having string
return string

parseJoin() protected method

join分析
protected parseJoin ( mixed $join ) : string
$join mixed
return string

parseLimit() protected method

limit分析
protected parseLimit ( $limit ) : string
return string

parseLock() protected method

设置锁机制
protected parseLock ( $lock = false ) : string
return string

parseOrder() protected method

order分析
protected parseOrder ( mixed $order ) : string
$order mixed
return string

parseSet() protected method

set分析
protected parseSet ( array $data ) : string
$data array
return string

parseTable() protected method

table分析
protected parseTable ( $tables ) : string
return string

parseThinkWhere() protected method

特殊条件分析
protected parseThinkWhere ( string $key, mixed $val ) : string
$key string
$val mixed
return string

parseValue() protected method

value分析
protected parseValue ( mixed &$value ) : string
$value mixed
return string

parseWhere() protected method

where分析
protected parseWhere ( mixed $where ) : string
$where mixed
return string

query() public method

执行查询 主要针对 SELECT, SHOW 等指令 返回数据集
public query ( string $str ) : mixed
$str string sql指令
return mixed

replace() public method

替换记录
public replace ( mixed $data, array $options = [] ) : false | integer
$data mixed 数据
$options array 参数表达式
return false | integer | integer

rollback() public method

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

select() public method

查找记录
public select ( array $options = [] ) : array
$options array 表达式
return array

selectInsert() public method

通过Select方式插入记录
public selectInsert ( string $fields, string $table, $options = [] ) : false | integer
$fields string 要插入的数据表字段名
$table string 要插入的数据表名
return false | integer | integer

startTrans() public method

启动事务
public startTrans ( )

switchConnect() public method

+---------------------------------------------------------- 切换数据库连接 +---------------------------------------------------------- +----------------------------------------------------------
public switchConnect ( integer $linkNum )
$linkNum integer 创建的连接序号 +---------------------------------------------------------- +----------------------------------------------------------

update() public method

更新记录
public update ( mixed $data, array $options ) : false | integer
$data mixed 数据
$options array 表达式
return false | integer | integer

Property Details

$_linkID protected property

当前连接ID
protected $_linkID

$autoFree protected property

是否自动释放查询结果
protected $autoFree

$beginTime protected property

SQL 执行时间记录
protected $beginTime

$comparison protected property

数据库表达式
protected $comparison

$config protected property

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

$connected protected property

是否已经连接数据库
protected $connected

$debug public property

是否显示调试信息 如果启用会在知识文件记录sql语句
public $debug

$error protected property

错误信息
protected $error

$lastInsID protected property

最后插入ID
protected $lastInsID

$linkID protected property

数据库连接ID 支持多个连接
protected $linkID

$numCols protected property

返回字段数
protected $numCols

$numRows protected property

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

$pconnect protected property

是否使用永久连接
protected $pconnect

$queryID protected property

当前查询ID
protected $queryID

$queryStr protected property

当前SQL指令
protected $queryStr

$selectSql protected property

查询表达式
protected $selectSql

$transTimes protected property

事务指令数
protected $transTimes