Properties

$debug

$debug : 

Type

$autoFree

$autoFree : 

Type

$pconnect

$pconnect : 

Type

$queryStr

$queryStr : 

Type

$lastInsID

$lastInsID : 

Type

$numRows

$numRows : 

Type

$numCols

$numCols : 

Type

$transTimes

$transTimes : 

Type

$error

$error : 

Type

$linkID

$linkID : 

Type

$queryID

$queryID : 

Type

$connected

$connected : 

Type

$config

$config : 

Type

$comparison

$comparison : 

Type

$selectSql

$selectSql : 

Type

$_mongo

$_mongo : 

Type

$_collection

$_collection : 

Type

$_dbName

$_dbName : 

Type

$_collectionName

$_collectionName : 

Type

$_cursor

$_cursor : 

Type

$_instance

$_instance : 

Type

Methods

__construct()

__construct(array  $config = '') 

架构函数 读取数据库配置信息

Parameters

array $config

数据库配置数组

connect()

connect(  $config = '',   $linkNum) 

连接数据库方法

Parameters

$config
$linkNum

free()

free() 

释放查询结果

query()

query(string  $str = '') : mixed

执行查询 主要针对 SELECT, SHOW 等指令 返回数据集

Parameters

string $str

sql指令

Throws

\ThinkExecption

Returns

mixed

execute()

execute(string  $code, array  $args = array()) : mixed

执行语句

Parameters

string $code

sql指令

array $args

参数

Returns

mixed

startTrans()

startTrans() : void

启动事务

Throws

\ThinkExecption

commit()

commit() : \boolen

用于非自动提交状态下面的查询提交

Throws

\ThinkExecption

Returns

\boolen

rollback()

rollback() : \boolen

事务回滚

Throws

\ThinkExecption

Returns

\boolen

getAll()

getAll() : array

获得所有的查询数据

Throws

\ThinkExecption

Returns

array

close()

close() 

关闭数据库

error()

error() : string

数据库错误信息

Returns

string

escapeString()

escapeString(string  $str) : string

SQL指令安全过滤

Parameters

string $str

SQL字符串

Returns

string

__destruct()

__destruct() 

析构方法

getInstance()

getInstance(  $db_config = '') : mixed

取得数据库类实例

Parameters

$db_config

Returns

mixed —

返回数据库驱动类

parseDSN()

parseDSN(string  $dsnStr) : array

DSN解析 格式: mysql://username:passwd@localhost:3306/DbName

Parameters

string $dsnStr

Returns

array

getLastSql()

getLastSql() : string

获取最近一次查询的sql语句

Returns

string

getLastInsID()

getLastInsID() : string

获取最近插入的ID

Returns

string

switchCollection()

switchCollection(string  $collection, string  $db = '', boolean  $master = true) : void

切换当前操作的Db和Collection

Parameters

string $collection

collection

string $db

db

boolean $master

是否主服务器

command()

command(array  $command = array()) : array

执行命令

Parameters

array $command

指令

Returns

array

insert()

insert(mixed  $data, array  $options = array(), boolean  $replace = false) : false

插入记录

Parameters

mixed $data

数据

array $options

参数表达式

boolean $replace

是否replace

Returns

false —

| integer

insertAll()

insertAll(array  $dataList, array  $options = array()) : boolean

插入多条记录

Parameters

array $dataList

数据

array $options

参数表达式

Returns

boolean

mongo_next_id()

mongo_next_id(string  $pk) : integer

生成下一条记录ID 用于自增非MongoId主键

Parameters

string $pk

主键名

Returns

integer

update()

update(mixed  $data, array  $options) : boolean

更新记录

Parameters

mixed $data

数据

array $options

表达式

Returns

boolean

delete()

delete(array  $options = array()) : false

删除记录

Parameters

array $options

表达式

Returns

false —

| integer

clear()

clear(array  $options = array()) : false

清空记录

Parameters

array $options

表达式

Returns

false —

| integer

select()

select(array  $options = array()) : \iterator

查找记录

Parameters

array $options

表达式

Returns

\iterator

find()

find(array  $options = array()) : array

查找某个记录

Parameters

array $options

表达式

Returns

array

count()

count(array  $options = array()) : \iterator

统计记录数

Parameters

array $options

表达式

Returns

\iterator

group()

group(  $keys,   $initial,   $reduce,   $options = array()) 

Parameters

$keys
$initial
$reduce
$options

getFields()

getFields(  $collection = '') : array

取得数据表的字段信息

Parameters

$collection

Returns

array

getTables()

getTables() 

取得当前数据库的collection信息

parseField()

parseField(mixed  $fields) : array

field分析

Parameters

mixed $fields

Returns

array

parseWhere()

parseWhere(mixed  $where) : array

where分析

Parameters

mixed $where

Returns

array

debug()

debug() 

数据库调试 记录当前SQL

parseSet()

parseSet(array  $data) : string

set分析

Parameters

array $data

Returns

string

parseOrder()

parseOrder(mixed  $order) : array

order分析

Parameters

mixed $order

Returns

array

parseLimit()

parseLimit(mixed  $limit) : array

limit分析

Parameters

mixed $limit

Returns

array

parseThinkWhere()

parseThinkWhere(string  $key, mixed  $val) : string

特殊条件分析

Parameters

string $key
mixed $val

Returns

string

parseWhereItem()

parseWhereItem(string  $key, mixed  $val) : array

where子单元分析

Parameters

string $key
mixed $val

Returns

array

parseConfig()

parseConfig(mixed  $db_config = '') : string

分析数据库配置信息,支持数组和DSN

Parameters

mixed $db_config

数据库配置信息

Returns

string