Method |
Description |
|
__call ( string $method, array $args ) : mixed |
利用__call方法实现一些特殊的Model方法 |
|
__construct ( Connection $connection = null, string $model = '' ) |
架构函数 |
|
alias ( mixed $alias ) |
指定数据表别名 |
|
avg ( string $field = '*' ) : float | integer |
AVG查询 |
|
batchQuery ( array $sql = [] ) : boolean |
批处理执行SQL语句
批处理的指令都认为是execute操作 |
|
bind ( mixed $key, mixed $value = false, integer $type = PDO::PARAM_STR ) |
参数绑定 |
|
buildSql ( boolean $sub = true ) : string |
创建子查询SQL |
|
cache ( mixed $key = true, integer $expire = null, string $tag = null ) |
查询缓存 |
|
chunk ( integer $count, callable $callback, string $column = null ) : boolean |
分批数据返回处理 |
|
column ( string $field, string $key = '' ) : array |
得到某个列的数组 |
|
comment ( string $comment ) |
查询注释 |
|
commit ( ) : void |
用于非自动提交状态下面的查询提交 |
|
connect ( mixed $config ) |
切换当前的数据库连接 |
|
count ( string $field = '*' ) : integer |
COUNT查询 |
|
delete ( mixed $data = null ) : integer |
删除记录 |
|
distinct ( string $distinct ) |
指定distinct查询 |
|
execute ( string $sql, array $bind = [] ) : integer |
执行语句 |
|
failException ( boolean $fail = true ) |
设置查询数据不存在是否抛出异常 |
|
fetchClass ( string $class ) |
指定数据集返回对象 |
|
fetchPdo ( boolean $pdo = true ) |
不主动获取数据集 |
|
fetchSql ( boolean $fetch = true ) |
获取执行的SQL语句 |
|
field ( mixed $field, boolean $except = false, string $tableName = '', string $prefix = '', string $alias = '' ) |
指定查询字段 支持字段排除和指定数据表 |
|
find ( array | string | Query | Closure $data = null ) : array | false | PDOStatement | string | Model |
查找单条记录 |
|
findOrFail ( array | string | Query | Closure $data = null ) : array | PDOStatement | string | Model |
查找单条记录 如果不存在则抛出异常 |
|
force ( string $force ) |
指定强制索引 |
|
getBind ( ) : array |
获取绑定的参数 并清空 |
|
getConfig ( string $name = '' ) : boolean |
获取数据库的配置参数 |
|
getConnection ( ) : Connection |
获取当前的数据库Connection对象 |
|
getFieldsBind ( $options ) |
获取当前数据表绑定信息 |
|
getFieldsType ( $options ) |
获取当前数据表字段类型 |
|
getLastInsID ( string $sequence = null ) : string |
获取最近插入的ID |
|
getLastSql ( ) : string |
获取最近一次查询的sql语句 |
|
getOptions ( string $name = '' ) : mixed |
获取当前的查询参数 |
|
getPartitionTableName ( array $data, string $field, array $rule = [] ) : string |
得到分表的的数据表名 |
|
getPk ( string | array $options = '' ) : string | array |
获取当前数据表的主键 |
|
getTable ( string $name = '' ) : string |
得到当前或者指定名称的数据表 |
|
getTableFields ( $options ) |
获取当前数据表字段信息 |
|
getTableInfo ( mixed $tableName = '', string $fetch = '' ) : mixed |
获取数据表信息 |
|
group ( string $group ) |
指定group查询 |
|
having ( string $having ) |
指定having查询 |
|
insert ( array $data, boolean $replace = false, boolean $getLastInsID = false, string $sequence = null ) : integer | string |
插入记录 |
|
insertAll ( array $dataSet ) : integer | string |
批量插入记录 |
|
insertGetId ( array $data, boolean $replace = false, string $sequence = null ) : integer | string |
插入记录并获取自增ID |
|
isBind ( string $key ) : boolean |
检测参数是否已经绑定 |
|
join ( mixed $join, mixed $condition = null, string $type = 'INNER' ) |
查询SQL组装 join |
|
limit ( mixed $offset, mixed $length = null ) |
指定查询数量 |
|
lock ( boolean $lock = false ) |
指定查询lock |
|
master ( ) |
设置从主服务器读取数据 |
|
max ( string $field = '*' ) : float | integer |
MAX查询 |
|
min ( string $field = '*' ) : float | integer |
MIN查询 |
|
name ( string $name ) |
指定默认的数据表名(不含前缀) |
|
order ( string | array $field, string $order = null ) |
指定排序 order('id','desc') 或者 order(['id'=>'desc','create_time'=>'desc']) |
|
page ( mixed $page, mixed $listRows = null ) |
指定分页 |
|
paginate ( integer | null $listRows = null, integer | boolean $simple = false, array $config = [] ) : Collection |
分页查询 |
|
parseSqlTable ( string $sql ) : string |
将SQL语句中的__TABLE_NAME__字符串替换成带前缀的表名(小写) |
|
partition ( array $data, string $field, array $rule = [] ) |
设置分表规则 |
|
pk ( string $pk ) |
指定数据表主键 |
|
query ( string $sql, array $bind = [], boolean $master = false, boolean | string $class = false ) : mixed |
执行查询 返回数据集 |
|
relation ( string $relation ) |
设置关联查询 |
|
rollback ( ) : void |
事务回滚 |
|
select ( array | string | Query | Closure $data = null ) : Collection | false | PDOStatement | string |
查找记录 |
|
selectInsert ( string $fields, string $table ) : integer | string |
通过Select方式插入记录 |
|
selectOrFail ( array | string | Query | Closure $data = null ) : array | PDOStatement | string | Model |
查找多条记录 如果不存在则抛出异常 |
|
sequence ( string $sequence = null ) |
设置自增序列名 |
|
setDec ( string $field, integer $step = 1, integer $lazyTime ) : integer | true |
字段值(延迟)减少 |
|
setField ( string | array $field, mixed $value = '' ) : integer |
设置记录的某个字段值
支持使用数据库字段和方法 |
|
setInc ( string $field, integer $step = 1, integer $lazyTime ) : integer | true |
字段值(延迟)增长 |
|
setTable ( string $table ) |
指定默认数据表名(含前缀) |
|
startTrans ( ) : void |
启动事务 |
|
strict ( boolean $strict = true ) |
设置是否严格检查字段名 |
|
sum ( string $field = '*' ) : float | integer |
SUM查询 |
|
table ( mixed $table ) |
指定当前操作的数据表 |
|
transaction ( callable $callback ) : mixed |
执行数据库事务 |
|
union ( mixed $union, boolean $all = false ) |
查询SQL组装 union |
|
update ( array $data ) : integer | string |
更新记录 |
|
using ( mixed $using ) |
USING支持 用于多表删除 |
|
value ( string $field, mixed $default = null ) : mixed |
得到某个字段的值 |
|
via ( string $via = '' ) |
设置当前字段添加的表别名 |
|
view ( $join, string | array $field = true, string | array $on = null, string $type = 'INNER' ) |
指定JOIN查询字段 |
|
where ( mixed $field, mixed $op = null, mixed $condition = null ) |
指定AND查询条件 |
|
whereOr ( mixed $field, mixed $op = null, mixed $condition = null ) |
指定OR查询条件 |
|
whereTime ( string $field, string $op, string | array $range = null ) |
查询日期或者时间 |
|
whereXor ( mixed $field, mixed $op = null, mixed $condition = null ) |
指定XOR查询条件 |
|
with ( string | array $with ) |
设置关联查询JOIN预查询 |
|
withField ( string | array $field ) |
关联预加载中 获取关联指定字段值
example:
Model::with(['relation' => function($query){
$query->withField("id,name");
}]) |
|