4.3.1 Model类
tableInfo 方法
作用:生成表结构信息
语法:tableInfo($table)
参数:string $table 待生成的表名
table 方法
作用:设置表名
语法:object table($table)
参数:string $table 待设置的表名
order 方法
作用:设置排序规则
语法:object order($order)
参数:string $order 待排序内容
where 方法
作用:设置sql条件
语法:object where($condition)
参数:string/array $condition 待执行的条件
示例:where(array('member_id'=>5)) 或 where('member_id=5')
on 方法
作用:设置关联表
语法:object on($string)
参数:string $string 待执行的条件
示例:on('store.member_id=member.member_id')
join 方法
作用:设置关联表,一般与on方法一起使用
语法:object join($string)
参数:string $string 关联类型
示例:join('inner')
limit 方法
作用:设置limit规则
语法:object limit($string)
参数:string $string 待排序内容
示例:limit(3),limit('3,6')
group 方法
作用:设置group by规则
语法:object limit($field)
参数:string $field 待分组字段
示例:group('store_id')
having 方法
作用:设置having规则
语法:object having($condition)
参数:string $condition 待筛选条件
示例:having('nc_count>3')
distinct 方法
作用:设置distinct,去重复数据
语法:object distinct()
参数:boolean true/false
page 方法
作用:设置每页显示数量
语法:object page($pagesize)
参数:integer $pagesize
min 方法
作用:取最小值
语法:integer min($field)
参数:string $field 字段名
示例:$model->table('member')->min('member_id')
max 方法
作用:取最大值,用法同min
count 方法
作用:取得记录总数
语法:integer count()
示例: $model->where('member_id>23')->count();
sum 方法
作用:取字段总和
语法:integer sum($field)
参数:string $field 字段名
示例:$model->table('product')->sum('price')
avg 方法
作用:取平均值
语法:integer avg($field)
参数:string $field 字段名
示例:$model->table('product')->avg('price')
select 方法:执行查询,详见3.3模型
find 方法:查询一条信息,详见3.3模型
delete 方法:执行删除,详见3.3模型
update 方法:执行更新,详见3.3模型
insert 方法:插入数据,详见3.3模型
inserAll 方法:批量插入,详见3.3模型
execute 方法:执行sql,主要为增、删、改操作,详见3.3模型
query 方法:执行sql,主要为查询操作,详见3.3模型
clear 方法
作用:清空表内容
语法: clear()
示例:$model->table('product')->clear()
getLastID 方法
作用:取得最新插入ID
getFields 方法
作用:取得当前操作表结构信息
setInc 方法
作用:自增操作
语法:setInc($field,$num)
参数:string $field 字段名
Int $num 增加数值
示例:$model->where(array('link_id'=>2))->setInc('link_sort',3)
setDec 方法
作用:自增操作
语法:setDec($field,$num)
参数:string $field 字段名
Int $num 增加数值
示例:$model->where(array('link_id'=>2))->setDec('link_sort',3)
cls 方法
作用:清空模型对象中的表名、where条件、排序等参数
语法:object cls()
示例:$model->cls()
showpage 方法
作用:显示分页链接
语法:string showpage($style)
参数: string $style 分页样式,可选值为1,2(默认),3
示例:$model->showpage();
Copyright ©2009 - 2014 shopnc.net.All rights reserved.
Powered By ShopNC