取得数据库类实例
static mixed
getInstance
()
DSN解析
格式: mysql://username:passwd@localhost:3306/DbName
static array
parseDSN
(string $dsnStr)
架构函数
Db
__construct
([array $config = ''])
Redefined in descendants as:
插入记录
false
add
(mixed $map, string $table, [mixed $multi = false])
-
mixed
$map: 数据
-
string
$table: 数据表名
-
mixed
$multi: 是否插入多条记录
插入多个记录
false
addAll
(mixed $map, string $table)
-
mixed
$map: 数据列表
-
string
$table: 数据表名
增加数据库连接(相同类型的)
void
addConnect
(mixed $config, [mixed $linkNum = null])
-
mixed
$config: 数据库连接信息
-
mixed
$linkNum: 创建的连接序号
字段和表名添加` 符合
保证指令中使用关键字不出错 针对mysql
mixed
addSpecialChar
( &$value, mixed $value)
自动判断进行查询或者执行操作
mixed
autoExec
([string $sql = ''], [ $lazy = false], [ $lock = false], [ $cache = false])
-
string
$sql: SQL指令
-
$lazy
-
$lock
-
$cache
数据库调试 记录当前SQL
void
debug
()
数据库操作方法
void
execute
([string $sql = ''], [ $lock = false])
加载数据库 支持配置文件或者 DSN
string
&factory
([mixed $db_config = ''])
-
mixed
$db_config: 数据库配置信息
字段格式化
mixed
fieldFormat
( &$value, mixed $value)
查找记录
ArrayObject
find
(mixed $where, string $tables, [string $fields = '*'], [string $order = null], [string $limit = null], [string $group = null], [string $having = null], [ $join = null], [boolean $cache = false], [boolean $lazy = false], [boolean $lock = false])
-
mixed
$where: 数据
-
string
$tables: 数据表名
-
string
$fields: 字段名
-
string
$order: 排序
-
string
$limit
-
string
$group
-
string
$having
-
boolean
$cache: 是否缓存
-
boolean
$lazy: 是否惰性加载
-
boolean
$lock: 是否加锁
-
$join
返回数据库的类型 如果使用PDO 会进一步分析
string
getDbType
()
获取最近一次查询的sql语句
string
getLastSql
()
初始化数据库连接
void
initConnect
([boolean $master = true])
是否为数据库更改操作
boolen
isMainIps
(string $query)
连接分布式服务器
void
multiConnect
([boolean $master = false])
fields分析
string
parseFields
(mixed $fields)
group分析
string
parseGroup
(mixed $group)
having分析
string
parseHaving
(string $having)
join分析
string
parseJoin
(mixed $join)
limit分析
string
parseLimit
(string $limit)
order分析
string
parseOrder
(mixed $order)
set分析
string
parseSets
(mixed $sets)
table分析
string
parseTables
(mixed $tables)
value分析
string
parseValues
(mixed $values)
where分析
string
parseWhere
(mixed $where)
查询次数更新或者查询
void
Q
([mixed $times = ''])
查询数据方法,支持动态缓存
动态缓存方式为可配置,默认为文件方式
mixed
query
([string $sql = ''], [boolean $cache = false], [boolean $lazy = false], [ $lock = false])
-
string
$sql: 查询语句
-
boolean
$cache: 是否缓存查询
-
boolean
$lazy: 是否惰性加载
-
$lock
删除记录
false
remove
(mixed $where, string $table, [string $limit = ''], [string $order = ''])
-
mixed
$where: 为条件Map、Array或者String
-
string
$table: 数据表名
-
string
$limit
-
string
$order
更新记录
false
save
(mixed $sets, string $table, string $where, [string $limit = 0], [string $order = ''], [boolean $lock = false])
-
mixed
$sets: 数据
-
string
$table: 数据表名
-
string
$where: 更新条件
-
string
$limit
-
string
$order
-
boolean
$lock: 是否加锁
减少某个字段的值
void
setDec
(string $field, string $table, $condition, [integer $step = 1], string $where)
-
string
$field: 要保存的字段名
-
string
$table: 数据表
-
string
$where: 保存条件
-
integer
$step
-
$condition
保存某个字段的值
void
setField
(string $field, string $value, string $table, $condition, [boolean $asString = false], string $where)
-
string
$field: 要保存的字段名
-
string
$value: 字段值
-
string
$table: 数据表
-
string
$where: 保存条件
-
boolean
$asString: 字段值是否为字符串
-
$condition
增加某个字段的值
void
setInc
(string $field, string $table, $condition, [integer $step = 1], string $where)
-
string
$field: 要保存的字段名
-
string
$table: 数据表
-
string
$where: 保存条件
-
integer
$step
-
$condition
设置锁机制
string
setLockMode
()
切换数据库连接
void
switchConnect
(integer $linkNum)
-
integer
$linkNum: 创建的连接序号
写入次数更新或者查询
void
W
([mixed $times = ''])