Class Db

Description

ThinkPHP 数据库中间层实现类

支持Mysql、MsSQL、Sqlite、Oracle、PgSQL等多种数据库 还可以使用PDO

Located in /Think/Db/Db.class.php (line 26)

Base
   |
   --Db
Direct descendents
Class Description
DbIbase Firebird数据库驱动类 剑雷 2007.12.28
DbMysql Mysql数据库驱动类
DbMysqli Mysqli数据库驱动类
DbPdo PDO数据库驱动类
DbPgsql Pgsql数据库驱动类 感谢刘格 2007-12-29 完善^_^
Variable Summary
mixed $autoCommit
mixed $autoFree
mixed $beginTime
mixed $comparison
mixed $config
mixed $connected
mixed $dbType
mixed $dbVersion
mixed $debug
mixed $error
mixed $fields
mixed $lastInsID
mixed $linkID
mixed $numCols
mixed $numRows
mixed $pconnect
mixed $queryID
mixed $queryStr
mixed $queryTimes
mixed $result
mixed $resultSet
mixed $resultType
mixed $transTimes
mixed $writeTimes
mixed $_linkID
Method Summary
static mixed getInstance ()
static array parseDSN (string $dsnStr)
Db __construct ([array $config = ''])
false add (mixed $map, string $table, [mixed $multi = false])
false addAll (mixed $map, string $table)
void addConnect (mixed $config, [mixed $linkNum = null])
mixed addSpecialChar ( &$value, mixed $value)
mixed autoExec ([string $sql = ''], [ $lazy = false], [ $lock = false], [ $cache = false])
void debug ()
void execute ([string $sql = ''], [ $lock = false])
string &factory ([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])
string getDbType ()
string getLastSql ()
void initConnect ([boolean $master = true])
boolen isMainIps (string $query)
ResultIterator lazyQuery ([string $sql = ''])
void multiConnect ([boolean $master = false])
string parseFields (mixed $fields)
string parseGroup (mixed $group)
string parseHaving (string $having)
string parseJoin (mixed $join)
string parseLimit (string $limit)
string parseOrder (mixed $order)
string parseSets (mixed $sets)
string parseTables (mixed $tables)
string parseValues (mixed $values)
string parseWhere (mixed $where)
void Q ([mixed $times = ''])
mixed query ([string $sql = ''], [boolean $cache = false], [boolean $lazy = false], [ $lock = false])
false remove (mixed $where, string $table, [string $limit = ''], [string $order = ''])
false save (mixed $sets, string $table, string $where, [string $limit = 0], [string $order = ''], [boolean $lock = false])
void setDec (string $field, string $table,  $condition, [integer $step = 1], string $where)
void setField (string $field, string $value, string $table,  $condition, [boolean $asString = false], string $where)
void setInc (string $field, string $table,  $condition, [integer $step = 1], string $where)
string setLockMode ()
void switchConnect (integer $linkNum)
void W ([mixed $times = ''])
Variables
mixed $autoCommit = true (line 39)
  • access: protected
mixed $autoFree = false (line 36)
  • access: protected
mixed $beginTime (line 102)
  • access: protected
mixed $comparison = array('eq'=>'=','neq'=>'!=','gt'=>'>','egt'=>'>=','lt'=>'<','elt'=>'<=','like'=>'LIKE','between'=>'BETWEEN','notnull'=>'IS NOT NULL','null'=>'IS NULL') (line 99)
  • access: protected
mixed $config = '' (line 96)
  • access: protected
mixed $connected = false (line 93)
  • access: protected
mixed $dbType = null (line 30)
  • access: protected
mixed $dbVersion = null (line 33)
  • access: protected
mixed $debug = false (line 42)
  • access: protected
mixed $error = '' (line 81)
  • access: protected
mixed $fields = null (line 60)
  • access: protected
mixed $lastInsID = null (line 63)
  • access: protected
mixed $linkID = array() (line 84)
  • access: protected
mixed $numCols = 0 (line 69)
  • access: protected
mixed $numRows = 0 (line 66)
  • access: protected
mixed $pconnect = false (line 45)
  • access: protected
mixed $queryID = null (line 90)
  • access: protected
mixed $queryStr = '' (line 48)
  • access: protected
mixed $queryTimes = 0 (line 72)
  • access: protected
mixed $result = null (line 51)
  • access: protected
mixed $resultSet = null (line 54)
  • access: protected
mixed $resultType = DATA_TYPE_ARRAY (line 57)
  • access: public
mixed $transTimes = 0 (line 78)
  • access: protected
mixed $writeTimes = 0 (line 75)
  • access: protected
mixed $_linkID = null (line 87)
  • access: protected
Methods
static getInstance (line 128)

取得数据库类实例

  • return: 返回数据库驱动类
  • access: public
static mixed getInstance ()
static parseDSN (line 340)

DSN解析

格式: mysql://username:passwd@localhost:3306/DbName

  • throws: ThinkExecption
  • access: public
static array parseDSN (string $dsnStr)
  • string $dsnStr
Constructor __construct (line 113)

架构函数

  • access: public
Db __construct ([array $config = ''])
  • array $config: 数据库配置数组

Redefined in descendants as:
add (line 1080)

插入记录

  • return: | integer
  • throws: ThinkExecption
  • access: public
false add (mixed $map, string $table, [mixed $multi = false])
  • mixed $map: 数据
  • string $table: 数据表名
  • mixed $multi: 是否插入多条记录
addAll (line 1130)

插入多个记录

  • return: | integer
  • throws: ThinkExecption
  • access: public
false addAll (mixed $map, string $table)
  • mixed $map: 数据列表
  • string $table: 数据表名
addConnect (line 219)

增加数据库连接(相同类型的)

  • throws: ThinkExecption
  • access: public
void addConnect (mixed $config, [mixed $linkNum = null])
  • mixed $config: 数据库连接信息
  • mixed $linkNum: 创建的连接序号
addSpecialChar (line 869)

字段和表名添加` 符合

保证指令中使用关键字不出错 针对mysql

  • throws: ThinkExecption
  • access: protected
mixed addSpecialChar ( &$value, mixed $value)
  • mixed $value
  • &$value
autoExec (line 1007)

自动判断进行查询或者执行操作

  • throws: ThinkExecption
  • access: public
mixed autoExec ([string $sql = ''], [ $lazy = false], [ $lock = false], [ $cache = false])
  • string $sql: SQL指令
  • $lazy
  • $lock
  • $cache
debug (line 374)

数据库调试 记录当前SQL

  • access: protected
void debug ()
execute (line 983)

数据库操作方法

  • throws: ThinkExecption
  • access: public
void execute ([string $sql = ''], [ $lock = false])
  • string $sql: 执行语句
  • $lock
factory (line 147)

加载数据库 支持配置文件或者 DSN

  • throws: ThinkExecption
  • access: public
string &factory ([mixed $db_config = ''])
  • mixed $db_config: 数据库配置信息
fieldFormat (line 839)

字段格式化

  • throws: ThinkExecption
  • access: protected
mixed fieldFormat ( &$value, mixed $value)
  • mixed $value
  • &$value
find (line 1041)

查找记录

  • throws: ThinkExecption
  • access: public
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
getDbType (line 413)

返回数据库的类型 如果使用PDO 会进一步分析

  • throws: ThinkExecption
  • access: protected
string getDbType ()
getLastSql (line 1332)

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

  • access: public
string getLastSql ()
initConnect (line 268)

初始化数据库连接

  • throws: ThinkExecption
  • access: protected
void initConnect ([boolean $master = true])
  • boolean $master: 主服务器
isMainIps (line 893)

是否为数据库更改操作

  • return: 如果是查询操作返回false
  • throws: ThinkExecption
  • access: public
boolen isMainIps (string $query)
  • string $query: SQL指令
lazyQuery (line 964)

延时查询方法

  • throws: ThinkExecption
  • access: public
ResultIterator lazyQuery ([string $sql = ''])
  • string $sql: 查询语句
multiConnect (line 291)

连接分布式服务器

  • throws: ThinkExecption
  • access: protected
void multiConnect ([boolean $master = false])
  • boolean $master: 主服务器
parseFields (line 718)

fields分析

  • throws: ThinkExecption
  • access: protected
string parseFields (mixed $fields)
  • mixed $fields
parseGroup (line 674)

group分析

  • throws: ThinkExecption
  • access: protected
string parseGroup (mixed $group)
  • mixed $group
parseHaving (line 697)

having分析

  • throws: ThinkExecption
  • access: protected
string parseHaving (string $having)
  • string $having
parseJoin (line 596)

join分析

  • throws: ThinkExecption
  • access: protected
string parseJoin (mixed $join)
  • mixed $join: Join表达式
parseLimit (line 625)

limit分析

  • throws: ThinkExecption
  • access: protected
string parseLimit (string $limit)
  • string $limit
parseOrder (line 573)

order分析

  • throws: ThinkExecption
  • access: protected
string parseOrder (mixed $order)
  • mixed $order: 排序
parseSets (line 777)

set分析

  • throws: ThinkExecption
  • access: protected
string parseSets (mixed $sets)
  • mixed $sets
parseTables (line 395)

table分析

  • throws: ThinkExecption
  • access: protected
string parseTables (mixed $tables)
  • mixed $tables: 数据表名
parseValues (line 753)

value分析

  • throws: ThinkExecption
  • access: protected
string parseValues (mixed $values)
  • mixed $values
parseWhere (line 454)

where分析

  • throws: ThinkExecption
  • access: protected
string parseWhere (mixed $where)
  • mixed $where: 查询条件
Q (line 1288)

查询次数更新或者查询

  • throws: ThinkExecption
  • access: public
void Q ([mixed $times = ''])
  • mixed $times
query (line 922)

查询数据方法,支持动态缓存

动态缓存方式为可配置,默认为文件方式

  • throws: ThinkExecption
  • access: public
mixed query ([string $sql = ''], [boolean $cache = false], [boolean $lazy = false], [ $lock = false])
  • string $sql: 查询语句
  • boolean $cache: 是否缓存查询
  • boolean $lazy: 是否惰性加载
  • $lock
remove (line 1178)

删除记录

  • return: | integer
  • throws: ThinkExecption
  • access: public
false remove (mixed $where, string $table, [string $limit = ''], [string $order = ''])
  • mixed $where: 为条件Map、Array或者String
  • string $table: 数据表名
  • string $limit
  • string $order
save (line 1202)

更新记录

  • return: | integer
  • throws: ThinkExecption
  • access: public
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: 是否加锁
setDec (line 1271)

减少某个字段的值

  • throws: ThinkExecption
  • access: public
void setDec (string $field, string $table,  $condition, [integer $step = 1], string $where)
  • string $field: 要保存的字段名
  • string $table: 数据表
  • string $where: 保存条件
  • integer $step
  • $condition
setField (line 1225)

保存某个字段的值

  • throws: ThinkExecption
  • access: public
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
setInc (line 1251)

增加某个字段的值

  • throws: ThinkExecption
  • access: public
void setInc (string $field, string $table,  $condition, [integer $step = 1], string $where)
  • string $field: 要保存的字段名
  • string $table: 数据表
  • string $where: 保存条件
  • integer $step
  • $condition
setLockMode (line 819)

设置锁机制

  • throws: ThinkExecption
  • access: protected
string setLockMode ()
switchConnect (line 245)

切换数据库连接

  • throws: ThinkExecption
  • access: public
void switchConnect (integer $linkNum)
  • integer $linkNum: 创建的连接序号
W (line 1312)

写入次数更新或者查询

  • throws: ThinkExecption
  • access: public
void W ([mixed $times = ''])
  • mixed $times

Documentation generated on Thu, 27 Mar 2008 08:20:30 +0000 by 塞北的雪