Model
class Model
Model
Traits
Properties
protected bool | $useMaster | 快捷方法-读是否强制使用主库 | from Base |
protected mixed | $cacheExpire | 查询数据缓存时间 | from Base |
protected null|string | $tablePrefix | 表前缀 | from Base |
protected string | $db | 数据库配置key | from Base |
protected null|string | $table | 表名 | from Base |
protected null | $primaryKey | 主键-不设置则自动从缓存获取 | from Base |
protected | $pdoFetchStyle | pdo获取数据的方式,默认返回数组 | from Base |
Methods
获取一个Model实例
根据条件是否成立执行对应的闭包
通过某个字段获取单条数据-快捷方法
通过某个字段获取多条数据-快捷方法
增加一条数据-快捷方法
No description
增加多条数据-快捷方法
插入或更新一条记录,当UNIQUE index or PRIMARY KEY存在的时候更新,不存在的时候插入 若AUTO_INCREMENT存在则返回 AUTO_INCREMENT 的值.
插入或替换多条记录
插入或替换一条记录 若AUTO_INCREMENT存在则返回 AUTO_INCREMENT 的值.
通过字段更新数据-快捷方法
通过主键删除数据-快捷方法
获取数据的总数
获取数据列表
以分页的方式获取数据列表
强制使用索引
定义操作的表
join内联结
leftJoin左联结
rightJoin右联结
标记本次查询不使用缓存
获取多条数据
分页获取数据
获取一条数据
获取上一INSERT的主键值
No description
Details
in Base at line 136
$this
cloneSelf()
clone一个自身用于复杂条件
in Base at line 146
closeDb(string $conf = 'default_db')
当程序连接N个db的时候用于释放于用连接以节省内存
in Base at line 163
Base
setCacheExpire(mixed $cacheExpire = null)
设置查询数据缓存时间
表数据有变动会自动更新缓存。设置为0表示表数据没变动时缓存不过期。 这边设置为3600意思是即使表数据没变动也让缓存每3600s失效一次,这样可以让缓存空间更合理的利用. 如果不想启用缓存直接配置为false 默认为null: 使用 db配置中的cache_expire
in Base at line 203
static Base
getInstance(null|string $table = null, null|string $tablePrefix = null, null|string|array $db = null)
获取一个Model实例
in Base at line 225
string
getTableName(bool $addTablePrefix = false, bool $addDbName = false)
获取表名
in Base at line 247
string
getDbConf()
获取当前Model的数据库配置串
in Base at line 302
static Base
__callStatic($dbMethod, $arguments)
当访问model中不存在的方法时直接调用相关model中的db()的相关方法
in Base at line 324
Base
when(bool $condition, callable $trueCallback, callable $falseCallback = null)
根据条件是否成立执行对应的闭包
in Base at line 342
mixed
getPrimaryKey(string $tableName = null, mixed $tablePrefix = null)
获取主键
in Base at line 349
__clone()
in Base at line 32
string|array
buildSql($offset = null, $limit = null, $isSelect = false)
构建sql
in Base at line 32
int
delete()
删除数据
in Base at line 32
int
count($field = '*', $isMulti = false, $useMaster = false)
获取 COUNT(字段名或*) 的结果
in Base at line 32
float
max($field = '*', $isMulti = false, $useMaster = false)
获取 MAX(字段名或*) 的结果
in Base at line 32
float
min($field = '*', $isMulti = false, $useMaster = false)
获取 MIN(字段名或*) 的结果
in Base at line 32
float
sum($field = '*', $isMulti = false, $useMaster = false)
获取 SUM(字段名或*) 的结果
in Base at line 32
float
avg($field = '*', $isMulti = false, $useMaster = false)
获取 AVG(字段名或*) 的结果
in QuickMethod at line 34
bool|array
getByColumn(mixed $val, string $column = null, string $tableName = null, mixed $tablePrefix = null)
通过某个字段获取单条数据-快捷方法
in QuickMethod at line 54
bool|array
getMultiByColumn(mixed $val, string $column = null, string $tableName = null, mixed $tablePrefix = null)
通过某个字段获取多条数据-快捷方法
in QuickMethod at line 73
int
set(array $data, string $tableName = null, mixed $tablePrefix = null)
deprecated
deprecated
in QuickMethod at line 87
int
insert(array $data, string $tableName = null, mixed $tablePrefix = null)
增加一条数据-快捷方法
in QuickMethod at line 105
bool
setMulti(array $field, array $data, string $tableName = null, mixed $tablePrefix = null, bool $openTransAction = true)
deprecated
deprecated
in QuickMethod at line 121
bool
insertMulti(array $field, array $data, string $tableName = null, mixed $tablePrefix = null, bool $openTransAction = true)
增加多条数据-快捷方法
in QuickMethod at line 140
int
upSet(array $data, array $up = [], array $upIgnoreField = [], string $tableName = null, mixed $tablePrefix = null)
插入或更新一条记录,当UNIQUE index or PRIMARY KEY存在的时候更新,不存在的时候插入 若AUTO_INCREMENT存在则返回 AUTO_INCREMENT 的值.
in QuickMethod at line 158
bool
replaceMulti(array $field, array $data, string $tableName = null, mixed $tablePrefix = null, bool $openTransAction = true)
插入或替换多条记录
in QuickMethod at line 175
int
replaceInto(array $data, string $tableName = null, mixed $tablePrefix = null)
插入或替换一条记录 若AUTO_INCREMENT存在则返回 AUTO_INCREMENT 的值.
in QuickMethod at line 193
bool
updateByColumn(int $val, array $data, string $column = null, string $tableName = null, mixed $tablePrefix = null)
通过字段更新数据-快捷方法
in QuickMethod at line 212
bool
delByColumn(mixed $val, string $column = null, string $tableName = null, mixed $tablePrefix = null)
通过主键删除数据-快捷方法
in QuickMethod at line 230
mixed
getTotalNums(null $pkField = null, string $tableName = null, mixed $tablePrefix = null)
获取数据的总数
in QuickMethod at line 249
array
getList(int $offset = 0, int $limit = 20, string|array $order = 'DESC', string $tableName = null, mixed $tablePrefix = null)
获取数据列表
in QuickMethod at line 273
array
getListByPaginate(int $limit = 20, string|array $order = 'DESC', string $tableName = null, mixed $tablePrefix = null)
以分页的方式获取数据列表
in QuickMethod at line 295
QuickMethod
forceIndex(string $index, string $tableName = null, string $tablePrefix = null)
强制使用索引
at line 34
Db|Model
table(|array $table = '', null $tablePrefix = null)
定义操作的表
at line 34
Db|Model
join(array $table, string $on, null $tablePrefix = null)
join内联结
at line 34
Db|Model
leftJoin(array $table, string $on, null $tablePrefix = null)
leftJoin左联结
at line 34
Db|Model
rightJoin(array $table, string $on, null $tablePrefix = null)
rightJoin右联结
at line 34
Db|Model
noCache()
标记本次查询不使用缓存
at line 34
array
select($offset = null, $limit = null, $useMaster = false, $fieldAsKey = false)
获取多条数据
at line 34
array
paginate($limit, $useMaster = false, $page = null, $fieldAsKey = false)
分页获取数据
at line 34
array|false
getOne($useMaster = false)
获取一条数据
at line 34
int
insertId()
获取上一INSERT的主键值